From: Jingbo Xu Date: Tue, 12 Sep 2023 13:51:33 +0000 (+0800) Subject: erofs-utils: lib: fix memory leaks in error paths of erofs_build_shared_xattrs_from_p... X-Git-Tag: v1.8~176 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=391aba1c212d136e453b2f73c8201c6457bbbf6f;p=platform%2Fupstream%2Ferofs-utils.git 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 Reviewed-by: Gao Xiang Link: https://lore.kernel.org/r/20230912135134.21307-1-jefflexu@linux.alibaba.com Signed-off-by: Gao Xiang --- 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); }