]> git.lizzy.rs Git - zlib.git/commitdiff
Fix bug in gzclose_w() when gzwrite() fails to allocate memory.
authorMark Adler <madler@alumni.caltech.edu>
Sat, 3 Mar 2012 17:28:00 +0000 (09:28 -0800)
committerMark Adler <madler@alumni.caltech.edu>
Sat, 3 Mar 2012 17:28:00 +0000 (09:28 -0800)
gzwrite.c

index 6e6d8a2c4c82578d04d29538096573ef10b23415..27cb3428e32f16f11b729ac8de1ceed786fb8be1 100644 (file)
--- a/gzwrite.c
+++ b/gzwrite.c
@@ -547,13 +547,15 @@ int ZEXPORT gzclose_w(file)
     }
 
     /* flush, free memory, and close file */
-    if (gz_comp(state, Z_FINISH) == -1)
-        ret = state->err;
-    if (!state->direct) {
-        (void)deflateEnd(&(state->strm));
-        free(state->out);
+    if (state->size) {
+        if (gz_comp(state, Z_FINISH) == -1)
+            ret = state->err;
+        if (!state->direct) {
+            (void)deflateEnd(&(state->strm));
+            free(state->out);
+        }
+        free(state->in);
     }
-    free(state->in);
     gz_error(state, Z_OK, NULL);
     free(state->path);
     if (close(state->fd) == -1)