From: Mika Lindqvist Date: Sat, 3 Oct 2020 23:52:56 +0000 (+0300) Subject: Fix memory leak in gz_compress() and add NULL check. X-Git-Tag: v2.0.0-RC1~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b80923956eb17e089c3aa900ff2e6e2b2a9c72d1;p=thirdparty%2Fzlib-ng.git Fix memory leak in gz_compress() and add NULL check. --- diff --git a/test/minigzip.c b/test/minigzip.c index 4cbb30f4..21cf8a36 100644 --- a/test/minigzip.c +++ b/test/minigzip.c @@ -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); }