Memory leak in PIL 1.1.3: ImagingCopyInfo

Pier Paolo Glave pierpaolo.glave at ciaolab.com
Thu Feb 27 16:45:19 CET 2003


Hi everybody,

I discovered a memory leak of 1040 bytes in PIL 1.1.3, regarding image
resize operations. This amount is exactly the size of the structure
used for palettes.

I found out that the problem is in ImagingCopyInfo routine (file
Storage.c), where a new palette is created for the new image, without
freeing the possibly pre-existing palette.

The memory leak can be avoided by adding a call to
ImagingPaletteDelete().
The code of ImagingCopyInfo becomes the following:

void
ImagingCopyInfo(Imaging destination, Imaging source)
{
    ImagingPaletteDelete(destination->palette);
    if (source->palette)
	destination->palette = ImagingPaletteDuplicate(source->palette);
}

instead of the old one:

void
ImagingCopyInfo(Imaging destination, Imaging source)
{
    if (source->palette)
	destination->palette = ImagingPaletteDuplicate(source->palette);
}

Regards,
--
Pier




More information about the Python-list mailing list