summaryrefslogtreecommitdiff
path: root/gzwrite.c
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2012-09-29 22:23:47 -0700
committerMark Adler <madler@alumni.caltech.edu>2012-09-29 22:37:55 -0700
commit0cf495a1ca941428c0b11e2307cad760ae44993e (patch)
tree6fe9dc258ebf611ec6b809d49a97d8a21b8b6dce /gzwrite.c
parentbd143f1c0a24075b2ec063a91f7b2b4b3b3b6ad8 (diff)
downloadzlib-0cf495a1ca941428c0b11e2307cad760ae44993e.tar.gz
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.
Diffstat (limited to 'gzwrite.c')
-rw-r--r--gzwrite.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/gzwrite.c b/gzwrite.c
index f53aace..79a69a5 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)