Hi Bob,
I am using graphicsmagick 1.3.22, Below is the code I am using to resize image, please take a look at it and suggest what could be the solution for mem leak.
Image image = (Image ) NULL;
ImageInfo *image_info;
ExceptionInfo exception;
InitializeMagick(NULL);
image_info = CloneImageInfo((ImageInfo *) NULL);
GetExceptionInfo(&exception);
strcpy(image_info->filename, inputSlateFile);
image = ReadImage(image_info, &exception);
if (exception.severity != UndefinedException)
{
CatchException(&exception);
}
if (!image)
{
goto program_exit;
}
//Potential reason of mem leak found in resize image but, valgrind reports in readimage. No //mem leak found when resize image is commented out.
image=ResizeImage(image, image->columns, image->rows, UndefinedFilter, 1.0, &image->exception);
strcpy(image->filename, outputSlateFile);
/ Write the output image /
if (!WriteImage (image_info,image))
{
CatchException(&image->exception);
goto program_exit;
}
program_exit:
if (image != (Image ) NULL)
{ DestroyImageList(image);
}
if (image_info != (ImageInfo ) NULL)
{
DestroyImageInfo(image_info);
}
DestroyExceptionInfo(&exception);
DestroyMagick();
valgrind is not reporting any memory leaks or other memory issue with the attached resize.c, which is compiled like
and then executed like
Bob
Hey Bob,
Thanks for the sample code. I was not taking separate Image structure for resize image. Now, it works fine. Thanks.
Sorry I did not thoroughly inspect your code. Overwriting the original image pointer would definitely cause problems. The C++ API makes such things much easier.