mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 10:46:16 +03:00
added cleanup to free dictionary memory in ZipEncode, fixes old comment about leaking memory from prior to when we had the cleanup mechanisim
This commit is contained in:
parent
4b4ef5f1e2
commit
49566b287e
6
encode.c
6
encode.c
|
@ -483,9 +483,7 @@ PyImaging_ZipEncoderNew(PyObject* self, PyObject* args)
|
|||
&dictionary, &dictionary_size))
|
||||
return NULL;
|
||||
|
||||
/* Copy to avoid referencing Python's memory, but there's no mechanism to
|
||||
free this memory later, so this function (and several others here)
|
||||
leaks. */
|
||||
/* Copy to avoid referencing Python's memory */
|
||||
if (dictionary && dictionary_size > 0) {
|
||||
/* malloc check ok, size comes from PyArg_ParseTuple */
|
||||
char* p = malloc(dictionary_size);
|
||||
|
@ -504,6 +502,7 @@ PyImaging_ZipEncoderNew(PyObject* self, PyObject* args)
|
|||
return NULL;
|
||||
|
||||
encoder->encode = ImagingZipEncode;
|
||||
encoder->cleanup = ImagingZipEncodeCleanup;
|
||||
|
||||
if (rawmode[0] == 'P')
|
||||
/* disable filtering */
|
||||
|
@ -638,6 +637,7 @@ PyImaging_JpegEncoderNew(PyObject* self, PyObject* args)
|
|||
if (get_packer(encoder, mode, rawmode) < 0)
|
||||
return NULL;
|
||||
|
||||
// Freed in JpegEncode, Case 5
|
||||
qarrays = get_qtables_arrays(qtables, &qtablesLen);
|
||||
|
||||
if (extra && extra_size > 0) {
|
||||
|
|
|
@ -474,6 +474,7 @@ extern int ImagingZipDecode(Imaging im, ImagingCodecState state,
|
|||
UINT8* buffer, int bytes);
|
||||
extern int ImagingZipEncode(Imaging im, ImagingCodecState state,
|
||||
UINT8* buffer, int bytes);
|
||||
extern int ImagingZipEncodeCleanup(ImagingCodecState state);
|
||||
#endif
|
||||
|
||||
typedef void (*ImagingShuffler)(UINT8* out, const UINT8* in, int pixels);
|
||||
|
|
|
@ -348,6 +348,24 @@ ImagingZipEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
|
|||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* Cleanup */
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
ImagingZipEncodeCleanup(ImagingCodecState state) {
|
||||
ZIPSTATE* context = (ZIPSTATE*) state->context;
|
||||
|
||||
if (context->dictionary) {
|
||||
free (context->dictionary);
|
||||
context->dictionary = NULL;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const char*
|
||||
ImagingZipVersion(void)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user