summaryrefslogtreecommitdiff
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
parentbd143f1c0a24075b2ec063a91f7b2b4b3b3b6ad8 (diff)
downloadzlib-0cf495a1ca941428c0b11e2307cad760ae44993e.tar.gz
zlib-0cf495a1ca941428c0b11e2307cad760ae44993e.tar.bz2
zlib-0cf495a1ca941428c0b11e2307cad760ae44993e.zip
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.
-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)
554 } 554 }
555 555
556 /* flush, free memory, and close file */ 556 /* flush, free memory, and close file */
557 if (state->size) { 557 if (gz_comp(state, Z_FINISH) == -1)
558 if (gz_comp(state, Z_FINISH) == -1) 558 ret = state->err;
559 ret = state->err; 559 if (!state->direct) {
560 if (!state->direct) { 560 (void)deflateEnd(&(state->strm));
561 (void)deflateEnd(&(state->strm)); 561 free(state->out);
562 free(state->out);
563 }
564 free(state->in);
565 } 562 }
563 if (state->size)
564 free(state->in);
566 gz_error(state, Z_OK, NULL); 565 gz_error(state, Z_OK, NULL);
567 free(state->path); 566 free(state->path);
568 if (close(state->fd) == -1) 567 if (close(state->fd) == -1)