aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJingbo Xu <jefflexu@linux.alibaba.com>2023-09-12 21:51:33 +0800
committerGao Xiang <hsiangkao@linux.alibaba.com>2023-09-12 22:19:35 +0800
commit391aba1c212d136e453b2f73c8201c6457bbbf6f (patch)
treea5820950cf3b4f40b2b570d8d687e061b5dc2378
parent914c7f667377ad82c174265840bbf4a52b2dae6c (diff)
downloaderofs-utils-391aba1c212d136e453b2f73c8201c6457bbbf6f.tar.gz
erofs-utils: lib: fix memory leaks in error paths of erofs_build_shared_xattrs_from_path()
Free the allocated sorted_n[] buffer when some error occurs. Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com> Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com> Link: https://lore.kernel.org/r/20230912135134.21307-1-jefflexu@linux.alibaba.com Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
-rw-r--r--lib/xattr.c5
1 files changed, 4 insertions, 1 deletions
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);
}