If the deflateInit2() called for the first gzwrite() failed with a
Z_MEM_ERROR, then a subsequent gzclose() would try to free an
already freed pointer. This fixes that.
/* 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)