Page 1 of 1

Unexpected memory usage in MagickGetImageFormat()

Posted: 2012-08-23T05:06:35-07:00
by dac
MagickGetImageFormat() returns a const char*, and since there is only a relatively small set of supported image formats, I expected it to return a pointer to a string literal.

However, it does not. Bizarrely, it allocates heap memory. Failure to return this memory results in a memory leak (typically only 4-5 bytes, but this locks up a 4K memory page, causing a >2Gb memory leak/week on my servers!)
Other functions, such as MagickGetImageChannelStatistics(), document that the returned pointer must be passed to MagickRelinquishMemory().

MagickGetImageFormat() should include the same documentation, or else it should stop allocating on the heap.

Re: Unexpected memory usage in MagickGetImageFormat()

Posted: 2012-08-23T05:27:58-07:00
by magick
MagickGetImageFormat() is incorrectly documented. We'll fix that by sometime tomorrow. It returns a char * which should be freed with free() when it is no longer needed.