Skip to contentSkip to conversation

erofs-utils: lib: fix gzran builder memory leak

PATCH New Ajay Rajera 1 participant 1 message Mar 21 Library code

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 erofs-utils: lib: fix gzran builder memory leak

When inflateInit2() fails, erofs_gzran_builder_init() returns ERR_PTR(-EFAULT) but forgets to free the previously allocated erofs_gzran_builder struct (gb), resulting in a memory leak.

Fix by calling free(gb) before returning the error.

---
 lib/gzran.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/gzran.c +3 -1
index dffb20a..8a01825 100644
@@ -50,8 +50,10 @@ struct erofs_gzran_builder *erofs_gzran_builder_init(struct erofs_vfile *vf,
 	strm->avail_in = 0;
 	strm->next_in = Z_NULL;
 	ret = inflateInit2(strm, 47);	/* automatic zlib or gzip decoding */
-	if (ret != Z_OK)
+	if (ret != Z_OK) {
+		free(gb);
 		return ERR_PTR(-EFAULT);
+	}
 	gb->vf = vf;
 	gb->span_size = span_size;
 	gb->totout = gb->totin = 0;
Signature · 1 line
2.51.0.windows.1