Free the allocated sorted_n[] buffer when error occurced.

Signed-off-by: Jingbo Xu <[email protected]>
---
 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

Reply via email to