Skip to content

Commit 828d455

Browse files
committed
Avoid a memory leak in fwrite(compress="gzip")
Previously, the zlib object zstrm was initialized whenever compression was enabled, at least in order to calculate the buffer size for the compressed data stream, but was only used for compression and subsequently deallocated only when there was a header with column names. Make sure to deflateEnd(&strm) even if there was no header.
1 parent 855886d commit 828d455

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/fwrite.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,12 @@ void fwriteMain(fwriteMainArgs args)
926926
}
927927
}
928928
}
929+
#ifndef NOZLIB
930+
else {
931+
// was unconditionally initialized for zbuffSize, not used for header
932+
deflateEnd(&strm);
933+
}
934+
#endif
929935
if (verbose)
930936
DTPRINT(_("Initialization done in %.3fs\n"), 1.0*(wallclock()-t0));
931937

0 commit comments

Comments
 (0)