From: Mark Adler Date: Sun, 30 Sep 2012 05:23:47 +0000 (-0700) Subject: Fix bug where gzopen(), gzclose() would write an empty file. X-Git-Tag: v1.2.7.1~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0cf495a1ca941428c0b11e2307cad760ae44993e;p=thirdparty%2Fzlib-ng.git Fix bug where gzopen(), gzclose() would write an empty file. A gzopen() to write (mode "w") followed immediately by a gzclose() would output an empty zero-length file. What it should do is write an empty gzip file, with the gzip header, empty deflate content, and gzip trailer totalling 20 bytes. This fixes it to do that. --- diff --git a/gzwrite.c b/gzwrite.c index f53aace49..79a69a5cd 100644 --- a/gzwrite.c +++ b/gzwrite.c @@ -554,15 +554,14 @@ int ZEXPORT gzclose_w(file) } /* flush, free memory, and close file */ - if (state->size) { - if (gz_comp(state, Z_FINISH) == -1) - ret = state->err; - if (!state->direct) { - (void)deflateEnd(&(state->strm)); - free(state->out); - } - free(state->in); + if (gz_comp(state, Z_FINISH) == -1) + ret = state->err; + if (!state->direct) { + (void)deflateEnd(&(state->strm)); + free(state->out); } + if (state->size) + free(state->in); gz_error(state, Z_OK, NULL); free(state->path); if (close(state->fd) == -1)