erofs-utils: lib: fix memory leaks in error paths of erofs_build_shared_xattrs_from_p...
authorJingbo Xu <jefflexu@linux.alibaba.com>
Tue, 12 Sep 2023 13:51:33 +0000 (21:51 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Tue, 12 Sep 2023 14:19:35 +0000 (22:19 +0800)
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>
lib/xattr.c

index d7557608417e965a7b66842e1264b4e47d5964ed..54a6ae2bccfb452920c9d954eca001a2129f130d 100644 (file)
@@ -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);
        }