lib: fix ownership leaks in FUSE cache insert functions on malloc failure (#321)

In rlc_insert and xac_insert (lib/fuse.c), both functions take
ownership of a parameter (link and xattrs respectively) but fail to
free it when their own malloc calls fail. Under memory pressure in a
long-running FUSE process, each failed cache insertion leaks the
owned resource.

Co-authored-by: Claude <nore@anthro.com>
This commit is contained in:
shivanayak
2026-03-09 23:59:54 +05:30
committed by GitHub
parent 91578639c6
commit 2fc54b8121

View File

@@ -1385,6 +1385,7 @@ xac_insert (guestfs_h *g,
entry = malloc (sizeof *entry);
if (entry == NULL) {
perrorf (g, "malloc");
guestfs_free_xattr_list (xattrs);
return -1;
}
@@ -1393,6 +1394,7 @@ xac_insert (guestfs_h *g,
if (entry->c.pathname == NULL) {
perrorf (g, "malloc");
free (entry);
guestfs_free_xattr_list (xattrs);
return -1;
}
if (STREQ (path, "/"))
@@ -1418,6 +1420,7 @@ rlc_insert (guestfs_h *g,
entry = malloc (sizeof *entry);
if (entry == NULL) {
perrorf (g, "malloc");
free (link);
return -1;
}
@@ -1426,6 +1429,7 @@ rlc_insert (guestfs_h *g,
if (entry->c.pathname == NULL) {
perrorf (g, "malloc");
free (entry);
free (link);
return -1;
}
if (STREQ (path, "/"))