erofs-utils: lib: Fix the memory leak in error path
authorSandeep Dhavale <dhavale@google.com>
Wed, 13 Sep 2023 22:11:02 +0000 (15:11 -0700)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Thu, 14 Sep 2023 02:53:38 +0000 (10:53 +0800)
If call to inflateInit2() fails, release the memory allocated for buff
before returning.

Signed-off-by: Sandeep Dhavale <dhavale@google.com>
Link: https://lore.kernel.org/r/20230913221104.429825-6-dhavale@google.com
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
lib/decompress.c

index 01f0141b5965481d56623e06fcbe6fdba40b3e7a..fe8a40c60516a1d36bf0612b7c90eb8422ebba2b 100644 (file)
@@ -126,8 +126,10 @@ static int z_erofs_decompress_deflate(struct z_erofs_decompress_req *rq)
        strm.avail_in = 0;
        strm.next_in = Z_NULL;
        ret = inflateInit2(&strm, -15);
-       if (ret != Z_OK)
+       if (ret != Z_OK) {
+               free(buff);
                return zerr(ret);
+       }
 
        strm.next_in = src + inputmargin;
        strm.avail_in = rq->inputsize - inputmargin;