From: Tassilo Horn <tassilo@member.fsf.org>
Date: Tue, 11 Jan 2011 20:14:13 +0000 (+0100)
Subject: * image.c (imagemagick_load_image, Finit_image_library): Free
X-Git-Tag: emacs-pretest-24.0.90~104^2~618^2~1322^2~239^2~2
X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=f853f59905cce4c7b2dc442ff5da1a10769730b0;p=emacs.git

* image.c (imagemagick_load_image, Finit_image_library): Free
intermediate image after creating a MagickWand from it.  Terminate
MagickWand environment after image loading.
---

diff --git a/src/ChangeLog b/src/ChangeLog
index 83524a5c048..a8755321a4d 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
+2011-01-11  Tassilo Horn  <tassilo@member.fsf.org>
+
+	* image.c (imagemagick_load_image, Finit_image_library): Free
+	intermediate image after creating a MagickWand from it.  Terminate
+	MagickWand environment after image loading.
+
 2011-01-10  Michael Albinus  <michael.albinus@gmx.de>
 
 	* dbusbind.c (Fdbus_register_service): Raise an error in case of
diff --git a/src/image.c b/src/image.c
index fd1b921056c..c39a9ef2817 100644
--- a/src/image.c
+++ b/src/image.c
@@ -7521,6 +7521,9 @@ imagemagick_load_image (/* Pointer to emacs frame structure.  */
      image.  Interface :index is same as for GIF.  First we "ping" the
      image to see how many sub-images it contains. Pinging is faster
      than loading the image to find out things about it.  */
+
+  /* MagickWandGenesis() initializes the imagemagick library.  */
+  MagickWandGenesis ();
   image = image_spec_value (img->spec, QCindex, NULL);
   ino = INTEGERP (image) ? XFASTINT (image) : 0;
   ping_wand = NewMagickWand ();
@@ -7549,6 +7552,7 @@ imagemagick_load_image (/* Pointer to emacs frame structure.  */
                     img->data.lisp_val));
 
   DestroyMagickWand (ping_wand);
+
   /* Now, after pinging, we know how many images are inside the
      file. If its not a bundle, just one.  */
 
@@ -7566,6 +7570,7 @@ imagemagick_load_image (/* Pointer to emacs frame structure.  */
       if (im_image != NULL)
 	{
 	  image_wand = NewMagickWandFromImage (im_image);
+          DestroyImage(im_image);
 	  status = MagickTrue;
 	}
       else
@@ -7576,7 +7581,7 @@ imagemagick_load_image (/* Pointer to emacs frame structure.  */
       image_wand = NewMagickWand ();
       status = MagickReadImageBlob (image_wand, contents, size);
     }
-  image_error ("im read failed", Qnil, Qnil);
+
   if (status == MagickFalse) goto imagemagick_error;
 
   /* If width and/or height is set in the display spec assume we want
@@ -7805,11 +7810,13 @@ imagemagick_load_image (/* Pointer to emacs frame structure.  */
 
   /* Final cleanup. image_wand should be the only resource left. */
   DestroyMagickWand (image_wand);
+  MagickWandTerminus ();
 
   return 1;
 
  imagemagick_error:
   DestroyMagickWand (image_wand);
+  MagickWandTerminus ();
   /* TODO more cleanup.  */
   image_error ("Error parsing IMAGEMAGICK image `%s'", img->spec, Qnil);
   return 0;
@@ -8681,8 +8688,6 @@ of `dynamic-library-alist', which see).  */)
 #if defined (HAVE_IMAGEMAGICK)
   if (EQ (type, Qimagemagick))
     {
-      /* MagickWandGenesis() initializes the imagemagick library.  */
-      MagickWandGenesis ();
       return CHECK_LIB_AVAILABLE (&imagemagick_type, init_imagemagick_functions,
 				  libraries);
     }