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

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