arrfab / rpms / zlib

Forked from rpms/zlib 5 years ago
Clone

Blame SOURCES/zlib-1.2.7-Fix-bug-where-gzopen-gzclose-would-write-an-empty-fi.patch

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