|
|
3d479f |
From 0cf495a1ca941428c0b11e2307cad760ae44993e Mon Sep 17 00:00:00 2001
|
|
|
3d479f |
From: Mark Adler <madler@alumni.caltech.edu>
|
|
|
3d479f |
Date: Sat, 29 Sep 2012 22:23:47 -0700
|
|
|
3d479f |
Subject: [PATCH] Fix bug where gzopen(), gzclose() would write an empty file.
|
|
|
3d479f |
|
|
|
3d479f |
A gzopen() to write (mode "w") followed immediately by a gzclose()
|
|
|
3d479f |
would output an empty zero-length file. What it should do is write
|
|
|
3d479f |
an empty gzip file, with the gzip header, empty deflate content,
|
|
|
3d479f |
and gzip trailer totalling 20 bytes. This fixes it to do that.
|
|
|
3d479f |
---
|
|
|
3d479f |
gzwrite.c | 15 +++++++--------
|
|
|
3d479f |
1 file changed, 7 insertions(+), 8 deletions(-)
|
|
|
3d479f |
|
|
|
3d479f |
diff --git a/gzwrite.c b/gzwrite.c
|
|
|
3d479f |
index f53aace..79a69a5 100644
|
|
|
3d479f |
--- a/gzwrite.c
|
|
|
3d479f |
+++ b/gzwrite.c
|
|
|
3d479f |
@@ -554,15 +554,14 @@ int ZEXPORT gzclose_w(file)
|
|
|
3d479f |
}
|
|
|
3d479f |
|
|
|
3d479f |
/* flush, free memory, and close file */
|
|
|
3d479f |
- if (state->size) {
|
|
|
3d479f |
- if (gz_comp(state, Z_FINISH) == -1)
|
|
|
3d479f |
- ret = state->err;
|
|
|
3d479f |
- if (!state->direct) {
|
|
|
3d479f |
- (void)deflateEnd(&(state->strm));
|
|
|
3d479f |
- free(state->out);
|
|
|
3d479f |
- }
|
|
|
3d479f |
- free(state->in);
|
|
|
3d479f |
+ if (gz_comp(state, Z_FINISH) == -1)
|
|
|
3d479f |
+ ret = state->err;
|
|
|
3d479f |
+ if (!state->direct) {
|
|
|
3d479f |
+ (void)deflateEnd(&(state->strm));
|
|
|
3d479f |
+ free(state->out);
|
|
|
3d479f |
}
|
|
|
3d479f |
+ if (state->size)
|
|
|
3d479f |
+ free(state->in);
|
|
|
3d479f |
gz_error(state, Z_OK, NULL);
|
|
|
3d479f |
free(state->path);
|
|
|
3d479f |
if (close(state->fd) == -1)
|
|
|
3d479f |
--
|
|
|
3d479f |
1.9.3
|
|
|
3d479f |
|