Unexpected memory usage in MagickGetImageFormat()
Posted: 2012-08-23T05:06:35-07:00
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.
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.