diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2012-09-29 22:23:47 -0700 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2012-09-29 22:37:55 -0700 |
commit | 0cf495a1ca941428c0b11e2307cad760ae44993e (patch) | |
tree | 6fe9dc258ebf611ec6b809d49a97d8a21b8b6dce | |
parent | bd143f1c0a24075b2ec063a91f7b2b4b3b3b6ad8 (diff) | |
download | zlib-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.c | 15 |
1 files changed, 7 insertions, 8 deletions
@@ -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) |