Maybe memory-management bug (Magick++/6.3.3-10)
Posted: 2007-10-05T16:44:21-07:00
I have been trying to use Magick++, version 6.3.3, with a debug malloc implementation from http://www.cs.berkeley.edu/~smcpeak/memory-errors/. This malloc/free does some very strict checks, and aborts at approximately this place in my code, which is creating reduced-size JPEG from an arbitrary image:
In my current test, the input image is also a JPEG.
This is based on what (I think) the Magick++ API does -- I first tried using Magick::Image::Write to a Magick::Blob, and was getting an error in free(); I 'expanded' what 'write', and the BlobRef destructor was doing, and got the above, and am still getting an error in free().
I also traced my malloc implementation (print every malloc() return value and every free()), and the pointer I'm being returned by ImageToBlob is never returned from any call to malloc().
Is RelinquishMagickMemory the correct call to dispose of a blob returned by ImageToBlob? If not, it looks like Magick++ is incorrect here.
Any help is appreciated.
Code: Select all
Magick::Image *image = new Magick::Image(imagepath);
// ...code here figures out reduced dimensions, scales 'image'
image->magick("JPEG");
//image->write(imgdata);
size_t length = 2048;
MagickLib::ExceptionInfo excep;
unsigned char *data = ImageToBlob(image->imageInfo(),
image->image(),
&length, &excep);
fprintf(stderr, "got blob for image: %p\n", data);
MagickLib::GetExceptionInfo(&excep);
Magick::throwException(excep);
MagickLib::DestroyExceptionInfo(&excep);
// ...code here memcpy's 'data' to its destination...
MagickLib::RelinquishMagickMemory(data); // aborts here in free()
This is based on what (I think) the Magick++ API does -- I first tried using Magick::Image::Write to a Magick::Blob, and was getting an error in free(); I 'expanded' what 'write', and the BlobRef destructor was doing, and got the above, and am still getting an error in free().
I also traced my malloc implementation (print every malloc() return value and every free()), and the pointer I'm being returned by ImageToBlob is never returned from any call to malloc().
Is RelinquishMagickMemory the correct call to dispose of a blob returned by ImageToBlob? If not, it looks like Magick++ is incorrect here.
Any help is appreciated.