fix another memory leak

This commit is contained in:
Alexander 2017-05-23 17:26:13 +03:00
parent 873d9ec089
commit 8c69132579
3 changed files with 22 additions and 0 deletions

View File

@ -779,6 +779,7 @@ PyImaging_ZipDecoderNew(PyObject* self, PyObject* args)
return NULL;
decoder->decode = ImagingZipDecode;
decoder->cleanup = ImagingZipDecodeCleanup;
((ZIPSTATE*)decoder->state.context)->interlaced = interlaced;

View File

@ -455,6 +455,7 @@ extern int ImagingXbmEncode(Imaging im, ImagingCodecState state,
#ifdef HAVE_LIBZ
extern int ImagingZipDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
extern int ImagingZipDecodeCleanup(ImagingCodecState state);
extern int ImagingZipEncode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
extern int ImagingZipEncodeCleanup(ImagingCodecState state);

View File

@ -86,6 +86,7 @@ ImagingZipDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
if (err < 0) {
state->errcode = IMAGING_CODEC_CONFIG;
free(context->previous);
context->previous = NULL;
return -1;
}
@ -127,6 +128,7 @@ ImagingZipDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
else
state->errcode = IMAGING_CODEC_CONFIG;
free(context->previous);
context->previous = NULL;
inflateEnd(&context->z_stream);
return -1;
}
@ -192,6 +194,7 @@ ImagingZipDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
default:
state->errcode = IMAGING_CODEC_UNKNOWN;
free(context->previous);
context->previous = NULL;
inflateEnd(&context->z_stream);
return -1;
}
@ -259,6 +262,7 @@ ImagingZipDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
state->errcode = IMAGING_CODEC_BROKEN; */
free(context->previous);
context->previous = NULL;
inflateEnd(&context->z_stream);
return -1; /* end of file (errcode=0) */
@ -275,4 +279,20 @@ ImagingZipDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
}
int ImagingZipDecodeCleanup(ImagingCodecState state){
/* called to fee the decompression engine when the decode terminates
due to a corrupt or truncated image
*/
ZIPSTATE* context = (ZIPSTATE*) state->context;
/* Clean up */
if (context->previous) {
inflateEnd(&context->z_stream);
free(context->previous);
context->previous = NULL;
}
return -1;
}
#endif