Memory leak coders/bmp.c

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
bearchun

Memory leak coders/bmp.c

Post by bearchun »

I got this problem on v6.6.2-10 and v6.6.3-0.

This is reproducible with some corrupt image files.

I'm using ImageMagick to do some batch operations on many JPEG files. Some of the input files were corrupted and it was causing a memory leak.

I had to use this patch to fix:

Code: Select all

> cat ImageMagick.patch 
diff -Naur ImageMagick-6.6.2-10/coders/bmp.c ImageMagick-6.6.2-10.new/coders/bmp.c
--- ImageMagick-6.6.2-10/coders/bmp.c	2010-06-02 17:53:06.000000000 -0700
+++ ImageMagick-6.6.2-10.new/coders/bmp.c	2010-07-02 22:47:01.000000000 -0700
@@ -909,8 +909,10 @@
           (void) LogMagickEvent(CoderEvent,GetMagickModule(),
             "  Reading pixels (%.20g bytes)",(double) length);
         count=ReadBlob(image,length,pixels);
-        if (count != (ssize_t) length)
+        if (count != (ssize_t) length) {
+          pixels=(unsigned char *) RelinquishMagickMemory(pixels);
           ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile");
+        }
       }
     else
       {
There could be more places where the function returns without free'ing 'pixels'
but this patch took care of the leak I was noticing.

Thanks. Sam.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Memory leak coders/bmp.c

Post by magick »

Thanks for the bug report and patch. We'll get it into the next point release of ImageMagick.
Post Reply