mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-07 21:33:28 +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))
|
&dictionary, &dictionary_size))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Copy to avoid referencing Python's memory, but there's no mechanism to
|
/* Copy to avoid referencing Python's memory */
|
||||||
free this memory later, so this function (and several others here)
|
|
||||||
leaks. */
|
|
||||||
if (dictionary && dictionary_size > 0) {
|
if (dictionary && dictionary_size > 0) {
|
||||||
/* malloc check ok, size comes from PyArg_ParseTuple */
|
/* malloc check ok, size comes from PyArg_ParseTuple */
|
||||||
char* p = malloc(dictionary_size);
|
char* p = malloc(dictionary_size);
|
||||||
|
@ -504,6 +502,7 @@ PyImaging_ZipEncoderNew(PyObject* self, PyObject* args)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
encoder->encode = ImagingZipEncode;
|
encoder->encode = ImagingZipEncode;
|
||||||
|
encoder->cleanup = ImagingZipEncodeCleanup;
|
||||||
|
|
||||||
if (rawmode[0] == 'P')
|
if (rawmode[0] == 'P')
|
||||||
/* disable filtering */
|
/* disable filtering */
|
||||||
|
@ -638,6 +637,7 @@ PyImaging_JpegEncoderNew(PyObject* self, PyObject* args)
|
||||||
if (get_packer(encoder, mode, rawmode) < 0)
|
if (get_packer(encoder, mode, rawmode) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
// Freed in JpegEncode, Case 5
|
||||||
qarrays = get_qtables_arrays(qtables, &qtablesLen);
|
qarrays = get_qtables_arrays(qtables, &qtablesLen);
|
||||||
|
|
||||||
if (extra && extra_size > 0) {
|
if (extra && extra_size > 0) {
|
||||||
|
|
|
@ -474,6 +474,7 @@ extern int ImagingZipDecode(Imaging im, ImagingCodecState state,
|
||||||
UINT8* buffer, int bytes);
|
UINT8* buffer, int bytes);
|
||||||
extern int ImagingZipEncode(Imaging im, ImagingCodecState state,
|
extern int ImagingZipEncode(Imaging im, ImagingCodecState state,
|
||||||
UINT8* buffer, int bytes);
|
UINT8* buffer, int bytes);
|
||||||
|
extern int ImagingZipEncodeCleanup(ImagingCodecState state);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef void (*ImagingShuffler)(UINT8* out, const UINT8* in, int pixels);
|
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;
|
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*
|
const char*
|
||||||
ImagingZipVersion(void)
|
ImagingZipVersion(void)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user