diff --git a/gzwrite.c b/gzwrite.c index 79a69a5..1b06cdd 100644 --- a/gzwrite.c +++ b/gzwrite.c @@ -556,12 +556,13 @@ 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 (state->size) { + if (!state->direct) { + (void)deflateEnd(&(state->strm)); + free(state->out); + } free(state->in); + } gz_error(state, Z_OK, NULL); free(state->path); if (close(state->fd) == -1)