[PATCH] zlib: fix resource leak when gzdirect failed

qiuguorui1 qiuguorui1 at huawei.com
Mon Nov 30 01:41:25 EST 2020


In function zlib_decompress_file, when gzdirect(fp) fails,
we should gzclose fp before return.

Fixes: d606837b56d46 ("Fix zlib/lzma decompression.")
Signed-off-by: qiuguorui1 <qiuguorui1 at huawei.com>
---
 kexec/zlib.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kexec/zlib.c b/kexec/zlib.c
index 9bc340d..3ed6bd6 100644
--- a/kexec/zlib.c
+++ b/kexec/zlib.c
@@ -60,7 +60,7 @@ char *zlib_decompress_file(const char *filename, off_t *r_size)
 	gzFile fp;
 	int errnum;
 	const char *msg;
-	char *buf;
+	char *buf = NULL;
 	off_t size = 0, allocated;
 	ssize_t result;
 
@@ -78,7 +78,7 @@ char *zlib_decompress_file(const char *filename, off_t *r_size)
 	}
 	if (gzdirect(fp)) {
 		/* It's not in gzip format */
-		return NULL;
+		goto fail;
 	}
 	allocated = 65536;
 	buf = xmalloc(allocated);
-- 
2.12.3




More information about the kexec mailing list