[PATCH 1/2] erofs-utils: lib: fix memleak in error path of erofs_build_shared_xattrs_from_path()
Jingbo Xu
jefflexu at linux.alibaba.com
Tue Sep 12 18:00:14 AEST 2023
Free the allocated sorted_n[] buffer when error occurced.
Signed-off-by: Jingbo Xu <jefflexu at linux.alibaba.com>
---
lib/xattr.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/lib/xattr.c b/lib/xattr.c
index d755760..54a6ae2 100644
--- a/lib/xattr.c
+++ b/lib/xattr.c
@@ -800,11 +800,14 @@ int erofs_build_shared_xattrs_from_path(struct erofs_sb_info *sbi, const char *p
qsort(sorted_n, shared_xattrs_count, sizeof(n), comp_shared_xattr_item);
buf = calloc(1, shared_xattrs_size);
- if (!buf)
+ if (!buf) {
+ free(sorted_n);
return -ENOMEM;
+ }
bh = erofs_balloc(XATTR, shared_xattrs_size, 0, 0);
if (IS_ERR(bh)) {
+ free(sorted_n);
free(buf);
return PTR_ERR(bh);
}
--
2.19.1.6.gb485710b
More information about the Linux-erofs
mailing list