Menu

#25 Mem leak due to ResizeImage

v1.0_(example)
closed
None
5
2015-11-22
2015-11-17
nikhil
No

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();

Discussion

  • Bob Friesenhahn

    Bob Friesenhahn - 2015-11-19

    valgrind is not reporting any memory leaks or other memory issue with the attached resize.c, which is compiled like

    gcc -o resize resize.c `GraphicsMagick-config --cppflags --cflags --ldflags --libs`
    

    and then executed like

    ./resize -geometry 800x600 input.jpg output.jpg
    

    Bob

     
  • nikhil

    nikhil - 2015-11-22

    Hey Bob,
    Thanks for the sample code. I was not taking separate Image structure for resize image. Now, it works fine. Thanks.

     
  • Bob Friesenhahn

    Bob Friesenhahn - 2015-11-22

    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.

     
  • Bob Friesenhahn

    Bob Friesenhahn - 2015-11-22
    • status: open --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB