diff --git a/0009-Fix-memory-leak-in-high-level-API-781.patch b/0009-Fix-memory-leak-in-high-level-API-781.patch new file mode 100644 index 0000000000000000000000000000000000000000..4cc42b9dcb07bc294b48193c20fd9a9669d351c2 --- /dev/null +++ b/0009-Fix-memory-leak-in-high-level-API-781.patch @@ -0,0 +1,69 @@ +From 98e0c3fd83dc5c90a8bbc8ba3faec3e2a96c4959 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Matthias=20G=C3=B6rgens?= +Date: Fri, 14 Apr 2023 19:19:03 +0800 +Subject: [PATCH] Fix memory leak in high level API (#781) + +Previously, in the high level API if we received a signal between +setting up signal handlers and processing INIT, we would leak + +``` +$ ./example/hello -s -d -f mountpoint/ +[9/9] Linking target example/hello_ll +FUSE library version: 3.14.1 +nullpath_ok: 0 + +================================================================= +==178330==ERROR: LeakSanitizer: detected memory leaks + +Direct leak of 352 byte(s) in 1 object(s) allocated from: + #0 0x7fbb19abf411 in __interceptor_calloc /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:77 + #1 0x7fbb1a0efd3b in fuse_fs_new ../lib/fuse.c:4814 + #2 0x7fbb1a0f02b5 in fuse_new_31 ../lib/fuse.c:4913 + #3 0x7fbb1a10ec5e in fuse_main_real ../lib/helper.c:345 + #4 0x5625db8ab418 in main ../example/hello.c:176 + #5 0x7fbb1983c78f (/usr/lib/libc.so.6+0x2378f) + +SUMMARY: AddressSanitizer: 352 byte(s) leaked in 1 allocation(s). +``` + +That's because `fuse_lowlevel.c`s `fuse_session_destroy` would only call +the user supplied `op.destroy`, if INIT had been processed, but the high +level API relied on `op.destroy` to free `f->fs`. + +This patch moves the freeing into `fuse_destroy` that will always be +called by our high-level API. +--- + lib/fuse.c | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +diff --git a/lib/fuse.c b/lib/fuse.c +index 5f872fa..1c0627e 100755 +--- a/lib/fuse.c ++++ b/lib/fuse.c +@@ -2670,7 +2670,6 @@ void fuse_fs_destroy(struct fuse_fs *fs) + fs->op.destroy(fs->user_data); + if (fs->m) + fuse_put_module(fs->m); +- free(fs); + } + + static void fuse_lib_destroy(void *data) +@@ -2679,7 +2678,6 @@ static void fuse_lib_destroy(void *data) + + fuse_create_context(f); + fuse_fs_destroy(f->fs); +- f->fs = NULL; + } + + static void fuse_lib_lookup(fuse_req_t req, fuse_ino_t parent, +@@ -5095,6 +5093,7 @@ void fuse_destroy(struct fuse *f) + free(f->name_table.array); + pthread_mutex_destroy(&f->lock); + fuse_session_destroy(f->se); ++ free(f->fs); + free(f->conf.modules); + free(f); + fuse_delete_context_key(); +-- +2.33.0 + diff --git a/fuse3.spec b/fuse3.spec index 07a7f8d205b63fdb7397a2f0242e484f3f83bf1b..0c618bfe21c13f184deabd023b66527a36e11771 100644 --- a/fuse3.spec +++ b/fuse3.spec @@ -2,7 +2,7 @@ Name: fuse3 Version: %{fuse3ver} -Release: 11 +Release: 12 Summary: User space File System of fuse3 License: GPL+ and LGPLv2+ URL: http://fuse.sf.net @@ -17,6 +17,7 @@ Patch5: 0005-Correct-errno-comparison-571.patch Patch6: 0006-Fix-fd-leak-with-clone_fd.patch Patch7: 0007-Fix-use-after-free-warning.patch Patch8: 0008-Disable-leak-suppression-773.patch +Patch9: 0009-Fix-memory-leak-in-high-level-API-781.patch BuildRequires: libselinux-devel, pkgconfig, systemd-udev, meson, fdupes BuildRequires: autoconf, automake, libtool, gettext-devel, ninja-build @@ -107,6 +108,9 @@ install -p -m 0644 %{SOURCE1} %{buildroot}%{_sysconfdir} %{_mandir}/man8/* %changelog +* Tue Feb 8 2024 yangyun -3.9.2-12 +- fix memory leak in high level api + * Wed Jul 12 2023 Zhiqiang Liu -3.9.2-11 - backport two upstream patches