comparison src/image.c @ 112152:f87a5809d0c2

Fix some resource leaks in ImageMagick image loader * src/image.c (imagemagick_load_image): Fix some resource leaks and error handling.
author Andreas Schwab <schwab@linux-m68k.org>
date Fri, 07 Jan 2011 23:33:32 +0100
parents 70be6bbb683b
children 3dff252e42ea 7df2e30d72ec
comparison
equal deleted inserted replaced
112151:5ba6192ecf75 112152:f87a5809d0c2
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
8 GNU Emacs is free software: you can redistribute it and/or modify 8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 it under the terms of the GNU General Public License as published by
7559 image_info->number_scenes = 1; 7559 image_info->number_scenes = 1;
7560 image_info->scene = ino; 7560 image_info->scene = ino;
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 {
7570 image_wand = NewMagickWand (); 7576 image_wand = NewMagickWand ();
7571 status = MagickReadImageBlob (image_wand, contents, size); 7577 status = MagickReadImageBlob (image_wand, contents, size);
7664 7670
7665 /* Finaly we are done manipulating the image, figure out resulting 7671 /* Finaly we are done manipulating the image, figure out resulting
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 {
7677 image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil); 7678 image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil);
7678 goto imagemagick_error; 7679 goto imagemagick_error;
7688 { 7689 {
7689 /* Try to create a x pixmap to hold the imagemagick pixmap. */ 7690 /* Try to create a x pixmap to hold the imagemagick pixmap. */
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 }
7696 7700
7697 /* Copy imagegmagick image to x with primitive yet robust pixel 7701 /* Copy imagegmagick image to x with primitive yet robust pixel
7700 7704
7701 /* Copy pixels from the imagemagick image structure to the x image map. */ 7705 /* Copy pixels from the imagemagick image structure to the x image map. */
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;
7708 } 7716 }
7709 7717
7734 char* exportdepth = imagedepth <= 8 ? "I" : "BGRP";/*"RGBP";*/ 7742 char* exportdepth = imagedepth <= 8 ? "I" : "BGRP";/*"RGBP";*/
7735 /* Try to create a x pixmap to hold the imagemagick pixmap. */ 7743 /* Try to create a x pixmap to hold the imagemagick pixmap. */
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 }
7742 7753
7743 7754
7796 DestroyMagickWand (image_wand); 7807 DestroyMagickWand (image_wand);
7797 7808
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;
7804 } 7816 }
7805 7817