]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Fix memory leak in gz_compress() and add NULL check.
authorMika Lindqvist <postmaster@raasu.org>
Sat, 3 Oct 2020 23:52:56 +0000 (02:52 +0300)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Fri, 9 Oct 2020 09:26:20 +0000 (11:26 +0200)
test/minigzip.c

index 4cbb30f4b3bcb089c442629304fde07c07f49b55..21cf8a36830b3d9771bbcecf0612450d725ca14f 100644 (file)
@@ -101,9 +101,12 @@ void gz_compress(FILE *in, gzFile out) {
     if (gz_compress_mmap(in, out) == Z_OK) return;
 #endif
     buf = (char *)calloc(BUFLEN, 1);
+    if (buf == NULL) perror("out of memory");
+
     for (;;) {
         len = (int)fread(buf, 1, BUFLEN, in);
         if (ferror(in)) {
+            free(buf);
             perror("fread");
             exit(1);
         }