diff options
| author | Andreas Schwab | 2011-01-07 23:33:32 +0100 |
|---|---|---|
| committer | Andreas Schwab | 2011-01-07 23:33:32 +0100 |
| commit | 466cbae99a69f4551726cd43adaf213e9d060f9e (patch) | |
| tree | ffd3cf3ff3808419cbd0317ee4cbfe003a1c4902 /src | |
| parent | 2b3f5bc80a2b8a7496a5d87cc98ffcce44e7b32e (diff) | |
| download | emacs-466cbae99a69f4551726cd43adaf213e9d060f9e.tar.gz emacs-466cbae99a69f4551726cd43adaf213e9d060f9e.zip | |
Fix some resource leaks in ImageMagick image loader
* src/image.c (imagemagick_load_image): Fix some resource leaks and
error handling.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 5 | ||||
| -rw-r--r-- | src/image.c | 30 |
2 files changed, 26 insertions, 9 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 7fb63964b6e..d4283dffffd 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2011-01-07 Andreas Schwab <schwab@linux-m68k.org> | ||
| 2 | |||
| 3 | * image.c (imagemagick_load_image): Fix some resource leaks and | ||
| 4 | error handling. | ||
| 5 | |||
| 1 | 2011-01-07 Chong Yidong <cyd@stupidchicken.com> | 6 | 2011-01-07 Chong Yidong <cyd@stupidchicken.com> |
| 2 | 7 | ||
| 3 | * fns.c (Fyes_or_no_p): Accept format string args. | 8 | * fns.c (Fyes_or_no_p): Accept format string args. |
diff --git a/src/image.c b/src/image.c index edfa208dd29..fd1b921056c 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | /* Functions for image support on window system. | 1 | /* Functions for image support on window system. |
| 2 | Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, | 2 | Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, |
| 3 | 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 | 3 | 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, |
| 4 | Free Software Foundation, Inc. | 4 | 2011 Free Software Foundation, Inc. |
| 5 | 5 | ||
| 6 | This file is part of GNU Emacs. | 6 | This file is part of GNU Emacs. |
| 7 | 7 | ||
| @@ -7561,9 +7561,15 @@ imagemagick_load_image (/* Pointer to emacs frame structure. */ | |||
| 7561 | exception = AcquireExceptionInfo (); | 7561 | exception = AcquireExceptionInfo (); |
| 7562 | 7562 | ||
| 7563 | im_image = ReadImage (image_info, exception); | 7563 | im_image = ReadImage (image_info, exception); |
| 7564 | CatchException (exception); | 7564 | DestroyExceptionInfo (exception); |
| 7565 | 7565 | ||
| 7566 | image_wand = NewMagickWandFromImage (im_image); | 7566 | if (im_image != NULL) |
| 7567 | { | ||
| 7568 | image_wand = NewMagickWandFromImage (im_image); | ||
| 7569 | status = MagickTrue; | ||
| 7570 | } | ||
| 7571 | else | ||
| 7572 | status = MagickFalse; | ||
| 7567 | } | 7573 | } |
| 7568 | else | 7574 | else |
| 7569 | { | 7575 | { |
| @@ -7666,11 +7672,6 @@ imagemagick_load_image (/* Pointer to emacs frame structure. */ | |||
| 7666 | width, height, and then transfer ownerwship to Emacs. */ | 7672 | width, height, and then transfer ownerwship to Emacs. */ |
| 7667 | height = MagickGetImageHeight (image_wand); | 7673 | height = MagickGetImageHeight (image_wand); |
| 7668 | width = MagickGetImageWidth (image_wand); | 7674 | width = MagickGetImageWidth (image_wand); |
| 7669 | if (status == MagickFalse) | ||
| 7670 | { | ||
| 7671 | image_error ("Imagemagick image get size failed", Qnil, Qnil); | ||
| 7672 | goto imagemagick_error; | ||
| 7673 | } | ||
| 7674 | 7675 | ||
| 7675 | if (! check_image_size (f, width, height)) | 7676 | if (! check_image_size (f, width, height)) |
| 7676 | { | 7677 | { |
| @@ -7690,6 +7691,9 @@ imagemagick_load_image (/* Pointer to emacs frame structure. */ | |||
| 7690 | if (!x_create_x_image_and_pixmap (f, width, height, 0, | 7691 | if (!x_create_x_image_and_pixmap (f, width, height, 0, |
| 7691 | &ximg, &img->pixmap)) | 7692 | &ximg, &img->pixmap)) |
| 7692 | { | 7693 | { |
| 7694 | #ifdef COLOR_TABLE_SUPPORT | ||
| 7695 | free_color_table (); | ||
| 7696 | #endif | ||
| 7693 | image_error("Imagemagick X bitmap allocation failure", Qnil, Qnil); | 7697 | image_error("Imagemagick X bitmap allocation failure", Qnil, Qnil); |
| 7694 | goto imagemagick_error; | 7698 | goto imagemagick_error; |
| 7695 | } | 7699 | } |
| @@ -7702,6 +7706,10 @@ imagemagick_load_image (/* Pointer to emacs frame structure. */ | |||
| 7702 | iterator = NewPixelIterator (image_wand); | 7706 | iterator = NewPixelIterator (image_wand); |
| 7703 | if (iterator == (PixelIterator *) NULL) | 7707 | if (iterator == (PixelIterator *) NULL) |
| 7704 | { | 7708 | { |
| 7709 | #ifdef COLOR_TABLE_SUPPORT | ||
| 7710 | free_color_table (); | ||
| 7711 | #endif | ||
| 7712 | x_destroy_x_image (ximg); | ||
| 7705 | image_error ("Imagemagick pixel iterator creation failed", | 7713 | image_error ("Imagemagick pixel iterator creation failed", |
| 7706 | Qnil, Qnil); | 7714 | Qnil, Qnil); |
| 7707 | goto imagemagick_error; | 7715 | goto imagemagick_error; |
| @@ -7736,6 +7744,9 @@ imagemagick_load_image (/* Pointer to emacs frame structure. */ | |||
| 7736 | if (!x_create_x_image_and_pixmap (f, width, height, imagedepth, | 7744 | if (!x_create_x_image_and_pixmap (f, width, height, imagedepth, |
| 7737 | &ximg, &img->pixmap)) | 7745 | &ximg, &img->pixmap)) |
| 7738 | { | 7746 | { |
| 7747 | #ifdef COLOR_TABLE_SUPPORT | ||
| 7748 | free_color_table (); | ||
| 7749 | #endif | ||
| 7739 | image_error("Imagemagick X bitmap allocation failure", Qnil, Qnil); | 7750 | image_error("Imagemagick X bitmap allocation failure", Qnil, Qnil); |
| 7740 | goto imagemagick_error; | 7751 | goto imagemagick_error; |
| 7741 | } | 7752 | } |
| @@ -7798,6 +7809,7 @@ imagemagick_load_image (/* Pointer to emacs frame structure. */ | |||
| 7798 | return 1; | 7809 | return 1; |
| 7799 | 7810 | ||
| 7800 | imagemagick_error: | 7811 | imagemagick_error: |
| 7812 | DestroyMagickWand (image_wand); | ||
| 7801 | /* TODO more cleanup. */ | 7813 | /* TODO more cleanup. */ |
| 7802 | image_error ("Error parsing IMAGEMAGICK image `%s'", img->spec, Qnil); | 7814 | image_error ("Error parsing IMAGEMAGICK image `%s'", img->spec, Qnil); |
| 7803 | return 0; | 7815 | return 0; |