Commit 466cbae9 authored by Andreas Schwab's avatar Andreas Schwab
Browse files

Fix some resource leaks in ImageMagick image loader

* src/image.c (imagemagick_load_image): Fix some resource leaks and
error handling.
parent 2b3f5bc8
2011-01-07 Andreas Schwab <schwab@linux-m68k.org>
* image.c (imagemagick_load_image): Fix some resource leaks and
error handling.
2011-01-07 Chong Yidong <cyd@stupidchicken.com> 2011-01-07 Chong Yidong <cyd@stupidchicken.com>
* fns.c (Fyes_or_no_p): Accept format string args. * fns.c (Fyes_or_no_p): Accept format string args.
......
/* Functions for image support on window system. /* Functions for image support on window system.
Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
Free Software Foundation, Inc. 2011 Free Software Foundation, Inc.
This file is part of GNU Emacs. This file is part of GNU Emacs.
...@@ -7561,9 +7561,15 @@ imagemagick_load_image (/* Pointer to emacs frame structure. */ ...@@ -7561,9 +7561,15 @@ imagemagick_load_image (/* Pointer to emacs frame structure. */
exception = AcquireExceptionInfo (); exception = AcquireExceptionInfo ();
im_image = ReadImage (image_info, exception); im_image = ReadImage (image_info, exception);
CatchException (exception); DestroyExceptionInfo (exception);
image_wand = NewMagickWandFromImage (im_image); if (im_image != NULL)
{
image_wand = NewMagickWandFromImage (im_image);
status = MagickTrue;
}
else
status = MagickFalse;
} }
else else
{ {
...@@ -7666,11 +7672,6 @@ imagemagick_load_image (/* Pointer to emacs frame structure. */ ...@@ -7666,11 +7672,6 @@ imagemagick_load_image (/* Pointer to emacs frame structure. */
width, height, and then transfer ownerwship to Emacs. */ width, height, and then transfer ownerwship to Emacs. */
height = MagickGetImageHeight (image_wand); height = MagickGetImageHeight (image_wand);
width = MagickGetImageWidth (image_wand); width = MagickGetImageWidth (image_wand);
if (status == MagickFalse)
{
image_error ("Imagemagick image get size failed", Qnil, Qnil);
goto imagemagick_error;
}
if (! check_image_size (f, width, height)) if (! check_image_size (f, width, height))
{ {
...@@ -7690,6 +7691,9 @@ imagemagick_load_image (/* Pointer to emacs frame structure. */ ...@@ -7690,6 +7691,9 @@ imagemagick_load_image (/* Pointer to emacs frame structure. */
if (!x_create_x_image_and_pixmap (f, width, height, 0, if (!x_create_x_image_and_pixmap (f, width, height, 0,
&ximg, &img->pixmap)) &ximg, &img->pixmap))
{ {
#ifdef COLOR_TABLE_SUPPORT
free_color_table ();
#endif
image_error("Imagemagick X bitmap allocation failure", Qnil, Qnil); image_error("Imagemagick X bitmap allocation failure", Qnil, Qnil);
goto imagemagick_error; goto imagemagick_error;
} }
...@@ -7702,6 +7706,10 @@ imagemagick_load_image (/* Pointer to emacs frame structure. */ ...@@ -7702,6 +7706,10 @@ imagemagick_load_image (/* Pointer to emacs frame structure. */
iterator = NewPixelIterator (image_wand); iterator = NewPixelIterator (image_wand);
if (iterator == (PixelIterator *) NULL) if (iterator == (PixelIterator *) NULL)
{ {
#ifdef COLOR_TABLE_SUPPORT
free_color_table ();
#endif
x_destroy_x_image (ximg);
image_error ("Imagemagick pixel iterator creation failed", image_error ("Imagemagick pixel iterator creation failed",
Qnil, Qnil); Qnil, Qnil);
goto imagemagick_error; goto imagemagick_error;
...@@ -7736,6 +7744,9 @@ imagemagick_load_image (/* Pointer to emacs frame structure. */ ...@@ -7736,6 +7744,9 @@ imagemagick_load_image (/* Pointer to emacs frame structure. */
if (!x_create_x_image_and_pixmap (f, width, height, imagedepth, if (!x_create_x_image_and_pixmap (f, width, height, imagedepth,
&ximg, &img->pixmap)) &ximg, &img->pixmap))
{ {
#ifdef COLOR_TABLE_SUPPORT
free_color_table ();
#endif
image_error("Imagemagick X bitmap allocation failure", Qnil, Qnil); image_error("Imagemagick X bitmap allocation failure", Qnil, Qnil);
goto imagemagick_error; goto imagemagick_error;
} }
...@@ -7798,6 +7809,7 @@ imagemagick_load_image (/* Pointer to emacs frame structure. */ ...@@ -7798,6 +7809,7 @@ imagemagick_load_image (/* Pointer to emacs frame structure. */
return 1; return 1;
imagemagick_error: imagemagick_error:
DestroyMagickWand (image_wand);
/* TODO more cleanup. */ /* TODO more cleanup. */
image_error ("Error parsing IMAGEMAGICK image `%s'", img->spec, Qnil); image_error ("Error parsing IMAGEMAGICK image `%s'", img->spec, Qnil);
return 0; return 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment