Page 1 of 1

ImageMagick-6.4.3-6 has memory leak for special jpg?

Posted: 2008-09-27T04:31:44-07:00
by zj0424
Im using ImageMagick-6.4.3-6
When I process a jpg like
http://www.acrosser.com.tw/DownLoad/200 ... 336734.jpg

my test code is core dump

Code: Select all

#include <Magick++.h>
#include <string>
#include<stdio.h>

using namespace std;
using namespace Magick;

#define nnum 6000000

int main(){

  FILE * fp;
  fp = fopen("readimage.jpg", "r");
  if(fp==NULL)
  {
    return 0;
  }
  char *test = new char[6000000];
  fread(test, sizeof(test), nnum, fp);

   Blob blob(test, sizeof(test)*nnum);
   Image image;
   try
    {
       image.read( blob );
    }
   catch( Exception &error_ )
    {
      printf("Caught exception:%s\n", error_.what());
        return EXIT_FAILURE;
    }
   delete test;
    return EXIT_SUCCESS;

}
where the valgrind show that In 64bit

==6513== 31,915 bytes in 1 blocks are definitely lost in loss record 20 of 22
==6513== at 0x4A05809: malloc (vg_replace_malloc.c:149)
==6513== by 0x5287171: NewXMLTree (in /usr/lib64/libMagickCore.so.1.0.0)
==6513== by 0x5235D16: GetImageProperty (in /usr/lib64/libMagickCore.so.1.0.0)
==6513== by 0x5237E2E: SetImageProfile (in /usr/lib64/libMagickCore.so.1.0.0)
==6513== by 0x9460591: (within /usr/lib64/ImageMagick-6.4.3/modules-Q16/coders/jpeg.so)
==6513== by 0x396BE10D1C: (within /usr/lib64/libjpeg.so.62.0.0)
==6513== by 0x396BE0EA1E: (within /usr/lib64/libjpeg.so.62.0.0)
==6513== by 0x396BE0CF61: jpeg_consume_input (in /usr/lib64/libjpeg.so.62.0.0)
==6513== by 0x396BE0D312: jpeg_read_header (in /usr/lib64/libjpeg.so.62.0.0)
==6513== by 0x9460FB3: (within /usr/lib64/ImageMagick-6.4.3/modules-Q16/coders/jpeg.so)
==6513== by 0x51BACCF: ReadImage (in /usr/lib64/libMagickCore.so.1.0.0)
==6513== by 0x51927DD: BlobToImage (in /usr/lib64/libMagickCore.so.1.0.0)

Is there anything memory leak?

anyway
in 32bit system there is
==18580== Source and destination overlap in memcpy(0x4D6B028, 0x47B2028, 24000000)
==18580== at 0x4006949: memcpy (mc_replace_strmem.c:402)
==18580== by 0x40405C0: Magick::BlobRef::BlobRef(void const*, unsigned) (in /usr/lib/libMagick++.so.1.0.0)
==18580== by 0x403FF22: Magick::Blob::Blob(void const*, unsigned) (in /usr/lib/libMagick++.so.1.0.0)
==18580== by 0x80489CC: main (magc.cpp:35)
and core dump too

please help!

Re: ImageMagick-6.4.3-6 has memory leak for special jpg?

Posted: 2008-09-27T08:22:07-07:00
by magick
We can reproduce the problem you posted about and will have a fix in the Subversion trunk by tomorrow. Thanks.

Re: ImageMagick-6.4.3-6 has memory leak for special jpg?

Posted: 2008-09-27T23:31:46-07:00
by zj0424
Thank you for your reply!

But I use trunk r12564 there isn't fix this bug,
So, Can you tell me what's version can fix it when done

Good luck

Re: ImageMagick-6.4.3-6 has memory leak for special jpg?

Posted: 2008-09-28T06:52:14-07:00
by magick
Grab the latest beta from ftp://ftp.imagemagick.org/pub/ImageMagick/beta. It has the patch to fix the problem you reported. The problem was your image had a corrupt XMP profile and the XML parser did not properly free memory.