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.