[PATCH v1 5/7] erofs-utils: lib: Fix the memory leak in error path

Sandeep Dhavale dhavale at google.com
Thu Sep 14 08:11:02 AEST 2023


If call to inflateInit2() fails, release the memory allocated for buff
before returning.

Signed-off-by: Sandeep Dhavale <dhavale at google.com>
---
 lib/decompress.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/decompress.c b/lib/decompress.c
index 01f0141..fe8a40c 100644
--- a/lib/decompress.c
+++ b/lib/decompress.c
@@ -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;
-- 
2.42.0.283.g2d96d420d3-goog



More information about the Linux-erofs mailing list