]> git.lizzy.rs Git - zlib.git/commitdiff
Fix bug where gzopen(), gzclose() would write an empty file.
authorMark Adler <madler@alumni.caltech.edu>
Sun, 30 Sep 2012 05:23:47 +0000 (22:23 -0700)
committerMark Adler <madler@alumni.caltech.edu>
Sun, 30 Sep 2012 05:37:55 +0000 (22:37 -0700)
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.

gzwrite.c

index f53aace491186bd4444d37bdd832307fb34fa218..79a69a5cd2fe3586500f41b856bd42ba8c90ab32 100644 (file)
--- 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)