erofs-utils: lib: fix memory leak in xattr handling
PATCH 1/1 erofs-utils: lib: fix memory leak in xattr handling
In android the LeakSanitizer reported memory leaks originating from functions like erofs_get_selabel_xattr.
The root cause is that the 'kvbuf' buffer, which is allocated to store xattr data, was not being freed when its owning 'xattr_item' struct was deallocated. The functions put_xattritem() and erofs_cleanxattrs() were freeing the xattr_item struct but neglected to free the kvbuf pointer within it.
This patch fixes the leak by adding the necessary free() calls for kvbuf in both functions.
--- lib/xattr.c | 2 ++ 1 file changed, 2 insertions(+)
lib/xattr.c +2 -0
@@ -194,6 +194,7 @@ static unsigned int put_xattritem(struct xattr_item *item)if (item->count >1 )return --item->count;hash_del (&item->node); +free ((void *)item->kvbuf);free (item);return 0 ; }
@@ -775,6 +776,7 @@ static void erofs_cleanxattrs(bool sharedxattrs)continue ;hash_del (&item->node); +free ((void *)item->kvbuf);free (item); }
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
Quoted 9 lines · Sandeep Dhavale
In android the LeakSanitizer reported memory leaks originating from functions like
erofs_get_selabel_xattr.The root cause is that the 'kvbuf' buffer, which is allocated to store xattr data, was not being freed when its owning '
xattr_item' struct was deallocated. The functionsput_xattritem()anderofs_cleanxattrs()were freeing thexattr_itemstruct but neglected to free the kvbuf pointer within it.
Quoted 4 lines
This patch fixes the leak by adding the necessary
free()calls for kvbuf in both functions.Signed-off-by Sandeep Dhavale <[email protected]>
Thanks,
Gao Xiang
Quoted 9 lines · Sandeep Dhavale
In android the LeakSanitizer reported memory leaks originating from functions like
erofs_get_selabel_xattr.The root cause is that the 'kvbuf' buffer, which is allocated to store xattr data, was not being freed when its owning '
xattr_item' struct was deallocated. The functionsput_xattritem()anderofs_cleanxattrs()were freeing thexattr_itemstruct but neglected to free the kvbuf pointer within it.
Quoted 4 lines
This patch fixes the leak by adding the necessary
free()calls for kvbuf in both functions.Signed-off-by Sandeep Dhavale <[email protected]>
Thanks,
Hi Chao,
Quoted 10 lines · Chao Yu
Quoted 9 lines · Sandeep Dhavale
In android the LeakSanitizer reported memory leaks originating from functions like
erofs_get_selabel_xattr.The root cause is that the 'kvbuf' buffer, which is allocated to store xattr data, was not being freed when its owning '
xattr_item' struct was deallocated. The functionsput_xattritem()anderofs_cleanxattrs()were freeing thexattr_itemstruct but neglected to free the kvbuf pointer within it.
Quoted 6 lines
Quoted 4 lines
This patch fixes the leak by adding the necessary
free()calls for kvbuf in both functions.Signed-off-by Sandeep Dhavale <[email protected]>Reviewed-by Chao Yu <[email protected]>
I released erofs-utils 1.8.10 hours ago to resolve some fragment mkfs regression so it won't be in appended.
But thanks for your review!
Thanks,
Gao Xiang
Quoted 2 lines
Thanks,