pcloudcc-lneely/pclsync
Levi Neely 9c103041c3
Fix memory leaks and bad-free on shutdown and crypto write (#375)
* Fix memory leaks in prpc_sockpath and prpc_main_loop

prpc_sockpath allocated home via ppath_home but never freed it before
returning. prpc_main_loop had three early-return paths that leaked
sockpath before the normal free at bind() success.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Fix memory leaks and bad-free in cache and crypto sector log

pcache.c: cache_timer and pcache_clean called pmem_free(he->value)
directly instead of he->free(he->value), skipping the registered free
callback. This caused all cached SSL connections, TLS sessions, and
crypto decoders to leak their internal mbedtls state on eviction and
shutdown. Same bug fixed in pcache_clean_oneof.

pfscrypto.c: ptree_for_each_element_call_safe passed bare free() to
free psync_sector_inlog_t nodes, but those are allocated via pmem_malloc
which prepends a 16-byte header. Add free_sector_inlog() helper that
calls pmem_free and use it at both call sites.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Fix bad-free in psync_interval_tree_free

Interval tree nodes are allocated via pmem_malloc, which prepends a
16-byte header. Passing bare free() to ptree_for_each_element_call_safe
freed the wrong address. Add free_interval_tree_node() helper that uses
pmem_free and use it in psync_interval_tree_free.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Fix bad-free in pcache callbacks using pmem-allocated values

pcache_add callers in ppagecache.c and pfstasks.c registered bare
free() as the eviction callback, but the stored values were allocated
with pmem_malloc/pmem_malloc_array which prepends a 16-byte header.
After the pcache_clean fix that now correctly invokes callbacks, these
bad-frees became fatal. Replace with static helpers that call pmem_free
with the correct subsystem.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Fix memory leaks in pfs_reopen_file_for_writing and clean_uploads_for_task

pfs.c: encsymkey from pcryptofolder_filencoder_key_get was freed on all
error paths in pfs_reopen_file_for_writing but not on the success path
that returns 1 after ppagecache_copy_to_file_locked.

pfsupload.c: fr from psql_fetchall_int was never freed in
clean_uploads_for_task; add pmem_free after the upload loop.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Fix spurious 'not mounted' error on FUSE3 shutdown

In FUSE3 mode, pfs_do_stop called fuse_unmount followed by fuse_exit.
The FUSE thread then called fuse_destroy, which tried to unmount again,
producing "fusermount3: not mounted".

For FUSE3, fuse_exit is sufficient to stop the loop; fuse_destroy handles
the unmount. Restrict the explicit fuse_unmount call to FUSE2 only.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Levi Neely <lkn@darkstar.example.net>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-10 13:51:14 +01:00
..
debug Fix debug build: compile error, false-positive abort, crash DB lock (#372) 2026-03-09 20:49:09 +01:00
LICENSE reorg source tree, link system mbedtls (#38) 2024-08-15 19:49:57 +02:00
paccountevents.h reorg source tree, link system mbedtls (#38) 2024-08-15 19:49:57 +02:00
papi.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
papi.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pbusinessaccount.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pbusinessaccount.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pcache.c Fix memory leaks and bad-free on shutdown and crypto write (#375) 2026-03-10 13:51:14 +01:00
pcache.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pcommands.h Fix #90, #109: Support 2FA when running as a daemon (#175) 2026-03-02 21:36:33 +01:00
pcompiler.h Code cleanup and readline for better CLI UX (#116) 2025-03-09 09:14:12 +01:00
pcontacts.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pcontacts.h reorg source tree, link system mbedtls (#38) 2024-08-15 19:49:57 +02:00
pcrc32c.c 102 create a psql namespace (#142) 2025-03-18 19:52:15 +01:00
pcrc32c.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pcrypto.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pcrypto.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pcryptofolder.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pcryptofolder.h access pcryptofolder directly from pclsync_lib (#125) 2025-03-09 19:58:00 +01:00
pdatabase.h eliminate pcompat (#92) 2025-02-28 22:47:32 +01:00
pdbg.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pdbg.h Fix pcl-0c1: make pdbg_runtime_level atomic (#343) 2026-03-03 20:08:18 +01:00
pdeflate.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pdeflate.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pdevice.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pdevice.h eliminate pcompat (#92) 2025-02-28 22:47:32 +01:00
pdevmon.c fix compile errors (#155) 2025-05-15 19:14:57 +02:00
pdevmon.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pdiff.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pdiff.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pdownload.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pdownload.h Code cleanup and readline for better CLI UX (#116) 2025-03-09 09:14:12 +01:00
pfile.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pfile.h eliminate pcompat (#92) 2025-02-28 22:47:32 +01:00
pfileops.c 102 create a psql namespace (#142) 2025-03-18 19:52:15 +01:00
pfileops.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pfolder.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pfoldersync.h move folder-related code from psynclib to pfolder 2025-04-18 15:23:50 +02:00
pfs.c Fix memory leaks and bad-free on shutdown and crypto write (#375) 2026-03-10 13:51:14 +01:00
pfs.h Add lock ordering assertions in debug builds (#370) 2026-03-08 15:38:41 +01:00
pfs_internal.h Fix debug build segfault: add strong overrides for psql_lock/unlock functions (#177) 2026-03-03 07:59:30 +01:00
pfscrypto.c Fix memory leaks and bad-free on shutdown and crypto write (#375) 2026-03-10 13:51:14 +01:00
pfscrypto.h Increase maintainability: namespace refactors for putil, pfs, and pfs sub-modules (#176) 2026-03-02 22:51:25 +01:00
pfsfolder.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pfsfolder.h Increase maintainability: namespace refactors for putil, pfs, and pfs sub-modules (#176) 2026-03-02 22:51:25 +01:00
pfsstatic.c Increase maintainability: namespace refactors for putil, pfs, and pfs sub-modules (#176) 2026-03-02 22:51:25 +01:00
pfsstatic.h Increase maintainability: namespace refactors for putil, pfs, and pfs sub-modules (#176) 2026-03-02 22:51:25 +01:00
pfstasks.c Fix memory leaks and bad-free on shutdown and crypto write (#375) 2026-03-10 13:51:14 +01:00
pfstasks.h Fix debug build segfault: add strong overrides for psql_lock/unlock functions (#177) 2026-03-03 07:59:30 +01:00
pfstasks_internal.h Fix debug build segfault: add strong overrides for psql_lock/unlock functions (#177) 2026-03-03 07:59:30 +01:00
pfsupload.c Fix memory leaks and bad-free on shutdown and crypto write (#375) 2026-03-10 13:51:14 +01:00
pfsupload.h Increase maintainability: namespace refactors for putil, pfs, and pfs sub-modules (#176) 2026-03-02 22:51:25 +01:00
pfsxattr.c Migrate to FUSE 3.x API (#350) 2026-03-09 21:51:00 +01:00
pfsxattr.h Increase maintainability: namespace refactors for putil, pfs, and pfs sub-modules (#176) 2026-03-02 22:51:25 +01:00
pintervaltree.c Fix memory leaks and bad-free on shutdown and crypto write (#375) 2026-03-10 13:51:14 +01:00
pintervaltree.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
plibs.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
plibs.h Increase maintainability: namespace refactors for putil, pfs, and pfs sub-modules (#176) 2026-03-02 22:51:25 +01:00
plist.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
plist.h Fix typo: rename psync_list_bulder_* to psync_list_builder_* (#302) 2026-03-03 12:23:16 +01:00
plocalnotify.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
plocalnotify.h Code cleanup and readline for better CLI UX (#116) 2025-03-09 09:14:12 +01:00
plocalscan.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
plocalscan.h Code cleanup and readline for better CLI UX (#116) 2025-03-09 09:14:12 +01:00
plocks.c Add deadlock detection with timeouts (#364) 2026-03-08 11:55:25 +01:00
plocks.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pmem.c Bug fixes: heap-use-after-free in pmem_realloc, auto-create FUSE mountpoint (#374) 2026-03-10 13:01:53 +01:00
pmem.h Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pnetlibs.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pnetlibs.h 98 create a pdbg namespace (#139) 2025-03-13 20:28:09 +01:00
pnotify.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pnotify.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pp2p.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pp2p.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
ppagecache.c Fix memory leaks and bad-free on shutdown and crypto write (#375) 2026-03-10 13:51:14 +01:00
ppagecache.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
ppassword.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
ppassword.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
ppassworddict.h reorg source tree, link system mbedtls (#38) 2024-08-15 19:49:57 +02:00
ppath.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
ppath.h Musl fixes (#143) 2025-04-13 09:11:11 +02:00
ppathstatus.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
ppathstatus.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pqevent.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pqevent.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
prand.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
prand.h eliminate pcompat (#92) 2025-02-28 22:47:32 +01:00
prpc.c Fix memory leaks and bad-free on shutdown and crypto write (#375) 2026-03-10 13:51:14 +01:00
prpc.h 130 use trustworthy location for log and socket (#134) 2025-03-11 19:03:58 +01:00
prun.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
prun.h eliminate pcompat (#92) 2025-02-28 22:47:32 +01:00
prunthrottled.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
prunthrottled.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pscanexts.h Appease the LSP server (#73) 2024-11-26 19:36:49 +01:00
psettings.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
psettings.h eliminate pcompat (#92) 2025-02-28 22:47:32 +01:00
pshm.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pshm.h #64 simplify messaging and #71 deserialize failed (#88) 2025-02-25 09:46:46 +01:00
psignal.c Fix debug build: compile error, false-positive abort, crash DB lock (#372) 2026-03-09 20:49:09 +01:00
psignal.h Fix debug build: compile error, false-positive abort, crash DB lock (#372) 2026-03-09 20:49:09 +01:00
psock.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
psock.h eliminate pcompat (#92) 2025-02-28 22:47:32 +01:00
psql.c Fix debug build: compile error, false-positive abort, crash DB lock (#372) 2026-03-09 20:49:09 +01:00
psql.h Fix pcl-10w: remove IS_DEBUG conditional from psql.h (#363) 2026-03-07 21:37:21 +01:00
psql_internal.h Fix debug build segfault: add strong overrides for psql_lock/unlock functions (#177) 2026-03-03 07:59:30 +01:00
pssl.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pssl.h 98 create a pdbg namespace (#139) 2025-03-13 20:28:09 +01:00
psslcerts.h Add new pCloud SSL certificate fingerprint (#172) 2026-03-01 09:14:29 +01:00
pstatus.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pstatus.h Code cleanup and readline for better CLI UX (#116) 2025-03-09 09:14:12 +01:00
psuggest.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
psuggest.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
psyncer.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
psynclib.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
psynclib.h Fix pcl-r0j: rename psync_delete_sync_by_folderid to pfolder_delete_sync_by_id (#361) 2026-03-07 19:54:21 +01:00
psys.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
psys.h Fix pcl-ivv: remove weak attribute from debug hooks (#362) 2026-03-07 20:18:51 +01:00
ptask.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
ptask.h 102 create a psql namespace (#142) 2025-03-18 19:52:15 +01:00
ptevent.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
ptevent.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
ptimer.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
ptimer.h 98 create a pdbg namespace (#139) 2025-03-13 20:28:09 +01:00
ptools.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
ptools.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
ptree.c 102 create a psql namespace (#142) 2025-03-18 19:52:15 +01:00
ptree.h Fix ptree_for_each_element loop termination condition (#319) 2026-03-03 15:29:44 +01:00
ptypes.h Appease the LSP server (#73) 2024-11-26 19:36:49 +01:00
publiclinks.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
publiclinks.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
pupload.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
pupload.h WIP: Decompose namespaces and other cleanup (#94) 2025-03-01 22:21:54 +01:00
putil.c Add memory accounting per subsystem (#371) 2026-03-08 21:47:22 +01:00
putil.h Increase maintainability: namespace refactors for putil, pfs, and pfs sub-modules (#176) 2026-03-02 22:51:25 +01:00
sockets.h Merge pclsync and poverlay_linux (#46) 2024-08-18 15:09:21 +02:00