Unexpected memory usage in MagickGetImageFormat()

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
dac
Posts: 1
Joined: 2012-08-23T04:45:32-07:00
Authentication code: 67789

Unexpected memory usage in MagickGetImageFormat()

Post 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.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Unexpected memory usage in MagickGetImageFormat()

Post 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.
Post Reply