Commit 60507209f36a328d692ef6a40e64b8b4d6137c04

Stefan Sperling 2018-07-13T11:26:37

fix a leak in got_inflate_to_mem_mmap()

diff --git a/got/Makefile b/got/Makefile
index 883c138..8dafd2f 100644
--- a/got/Makefile
+++ b/got/Makefile
@@ -17,7 +17,7 @@ DEBUG = -O0 -pg
 DEBUG = -O0 -g
 .endif
 CFLAGS += -Werror -Wall -Wstrict-prototypes -Wunused-variable
-#CFLAGS += -DGOT_PACK_NO_MMAP
+CFLAGS += -DGOT_PACK_NO_MMAP
 #CFLAGS += -DGOT_NO_OBJ_CACHE
 
 # For now, default to installing binary in ~/bin
diff --git a/lib/inflate.c b/lib/inflate.c
index 89c49ef..75303da 100644
--- a/lib/inflate.c
+++ b/lib/inflate.c
@@ -301,8 +301,11 @@ got_inflate_to_mem_mmap(uint8_t **outbuf, size_t *outlen, uint8_t *map,
 	if (*outbuf == NULL)
 		return got_error_from_errno();
 	err = got_inflate_init(&zb, *outbuf, GOT_ZSTREAM_BUFSIZE);
-	if (err)
+	if (err) {
+		free(*outbuf);
+		*outbuf = NULL;
 		return err;
+	}
 
 	*outlen = 0;