unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Tassilo Horn <tassilo@member.fsf.org>
To: joakim@verona.se
Cc: emacs-devel@gnu.org
Subject: Re: Using the ImageMagick backend seems to leak memory
Date: Tue, 11 Jan 2011 10:53:24 +0100	[thread overview]
Message-ID: <878vyrpy0b.fsf@member.fsf.org> (raw)
In-Reply-To: <m362tv3hqk.fsf@verona.se> (joakim@verona.se's message of "Tue, 11 Jan 2011 10:35:47 +0100")

joakim@verona.se writes:

Hi Joakim,

>> this is driving me nuts.  I've already tried modifying
>> imagemagick_load_image() with some messages, and so that it always
>> does MagickWandGenesis() first and MagickWandTerminus() after
>> destroying the last MagickWand.  It does so, but that didn't help...

[patch below]

>> One strangeness I found is the line
>>
>>     image_error ("im read failed", Qnil, Qnil);
>>
>> which is called unconditionally in imagemagick_load_image().  Why?
>
> Thats supposed to be an error condition exit only.
> Isnt there a return statement before?

No, neither before nor after.

> I havent yet tried to recreate your problem, but my experience when I
> worked on the patch was that I got memory issues when working with
> image bundle files.

That's not the case here.  I load one single PNG (or whatever) file, or
in the case of doc-view, several PNG files one after the other.

> Also the imagemagick team was very helpful in providing fixes in their
> code.

I tried to get in contact, but my posting via Gmane was rejected and I
got no response on ##imagemagick.  Then I tried to register with their
web forum, but I still haven't got the confirmation mail...

> Have you tried to install a development version of imagemagick?

No, I'm running the released version 6.6.5.6.  And as I've said in
another mail, the MagickWand example code with my small changes works
just fine with that version, i.e., memory is given back...

And the basic order of MagickWand function invocations applied in emacs
seems to match the example.  Maybe some emacs/X structures share data
with MagickWand structures, so that the latter cannot be freed when
destroying the MagickWand or calling MagickWandTerminus?

Bye,
Tassilo

Here's a patch with my unsuccessful changes to image.c.  Maybe it's of
some use...

--8<---------------cut here---------------start------------->8---
=== modified file 'src/image.c'
--- src/image.c	2011-01-07 22:33:32 +0000
+++ src/image.c	2011-01-11 08:11:07 +0000
@@ -7521,9 +7521,12 @@
      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 ();
+  message ("MagickWandGenesis ();");
   image = image_spec_value (img->spec, QCindex, NULL);
   ino = INTEGERP (image) ? XFASTINT (image) : 0;
   ping_wand = NewMagickWand ();
+  message ("ping_wand = NewMagickWand ();");
   MagickSetResolution (ping_wand, 2, 2);
   if (filename != NULL)
     {
@@ -7539,6 +7542,7 @@
       image_error ("Invalid image number `%s' in image `%s'",
 		   image, img->spec);
       DestroyMagickWand (ping_wand);
+      message ("DestroyMagickWand (ping_wand);");
       return 0;
     }
 
@@ -7549,6 +7553,9 @@
                     img->data.lisp_val));
 
   DestroyMagickWand (ping_wand);
+  message ("DestroyMagickWand (ping_wand);");
+
+
   /* Now, after pinging, we know how many images are inside the
      file. If its not a bundle, just one.  */
 
@@ -7566,6 +7573,7 @@
       if (im_image != NULL)
 	{
 	  image_wand = NewMagickWandFromImage (im_image);
+	  message ("image_wand = NewMagickWand ();");
 	  status = MagickTrue;
 	}
       else
@@ -7574,6 +7582,7 @@
   else
     {
       image_wand = NewMagickWand ();
+      message ("image_wand = NewMagickWand ();");
       status = MagickReadImageBlob (image_wand, contents, size);
     }
   image_error ("im read failed", Qnil, Qnil);
@@ -7805,11 +7814,18 @@
 
   /* Final cleanup. image_wand should be the only resource left. */
   DestroyMagickWand (image_wand);
+  message ("DestroyMagickWand (image_wand);");
+  MagickWandTerminus ();
+  message ("MagickWandTerminus ();");
 
   return 1;
 
  imagemagick_error:
   DestroyMagickWand (image_wand);
+  message ("Error case: DestroyMagickWand (image_wand);");
+  MagickWandTerminus ();
+  message ("MagickWandTerminus ();");
+
   /* TODO more cleanup.  */
   image_error ("Error parsing IMAGEMAGICK image `%s'", img->spec, Qnil);
   return 0;
@@ -8681,8 +8697,6 @@
 #if defined (HAVE_IMAGEMAGICK)
   if (EQ (type, Qimagemagick))
     {
-      /* MagickWandGenesis() initializes the imagemagick library.  */
-      MagickWandGenesis ();
       return CHECK_LIB_AVAILABLE (&imagemagick_type, init_imagemagick_functions,
 				  libraries);
     }
--8<---------------cut here---------------end--------------->8---



  reply	other threads:[~2011-01-11  9:53 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-06  7:51 Using the ImageMagick backend seems to leak memory Tassilo Horn
2011-01-06  9:02 ` joakim
2011-01-06 10:20   ` Tassilo Horn
2011-01-07  4:17 ` Jashy
2011-01-07  4:59   ` Miles Bader
2011-01-07  6:27     ` Stephen J. Turnbull
2011-01-07  7:25       ` Miles Bader
2011-01-07  8:28     ` Tassilo Horn
2011-01-07 22:39       ` Andreas Schwab
2011-01-10 10:34         ` Tassilo Horn
2011-01-10 13:28           ` Jashy
2011-01-10 13:56             ` Tassilo Horn
2011-01-10 14:36               ` Jashy
2011-01-11 10:14                 ` Jashy
2011-01-11 10:59           ` joakim
2011-01-11 14:17       ` joakim
2011-01-11 14:38         ` joakim
2011-01-11 17:43         ` Tassilo Horn
2011-01-11 18:11           ` joakim
2011-01-11 19:10             ` Tassilo Horn
2011-01-11 19:35               ` joakim
2011-01-11 19:55                 ` Tassilo Horn
2011-01-12  1:47               ` Stefan Monnier
2011-01-12  7:37                 ` Tassilo Horn
2011-01-10 21:47 ` Tassilo Horn
2011-01-11  8:47   ` Tassilo Horn
2011-01-11  9:35     ` joakim
2011-01-11  9:53       ` Tassilo Horn [this message]
2011-01-11  9:54       ` joakim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878vyrpy0b.fsf@member.fsf.org \
    --to=tassilo@member.fsf.org \
    --cc=emacs-devel@gnu.org \
    --cc=joakim@verona.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).