Closed lgalfaso closed 11 months ago
No, you do not need to call deflateEnd()
, and no, deflateInit()
will not leak. deflateInit()
frees all memory successfully allocated so far upon an allocation failure. (See https://github.com/madler/zlib/blob/develop/deflate.c#L507 .)
Nothing bad will happen if you do, nevertheless, call deflateEnd()
after deflateInit()
returns an error. You will simply get a Z_STREAM_ERROR
return code.
So, either is fine.
It is not clear whether
deflateEnd
should be called whenever an error is returned fromdeflateInit
. Looking at the implementation ofcompress
it looks like it should not be called, but given thatdeflateInit
makes some allocations, then an error indeflateInit
looks like it will leak.Note: the only way I can see this happening is if some of the allocations succeed and some do not, so this would be very unlikely.