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