Magick++ memory leak

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
jolz

Magick++ memory leak

Post by jolz »

There's a memory leak in exception handling.
readImages() calls GetExceptionInfo() and doesn't call DestroyExceptionInfo(), because of throw (looks like a great place for RAII)
Actually resources are released in throwException(), but then they are again acquired in the same function.

By the way, I find throwing warning very inconvenient - I have to catch warning after every call if I want to ignore it or just log - it makes C++ almost like C.
zeugman

Re: Magick++ memory leak

Post by zeugman »

I've the same problem.
On valgrind blocks are definitively lost here :

==9455== by 0x51986E1: GetExceptionInfo (exception.c:415)
==9455== by 0x4E53525: Magick::Image::read(Magick::Blob const&) (Image.cpp:1448)
and here
==9455== by 0x4E4B3EE: Magick::throwException(MagickLib::_ExceptionInfo&) (Exception.cpp:297)
==9455== by 0x4E5356A: Magick::Image::read(Magick::Blob const&) (Image.cpp:1454)
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Magick++ memory leak

Post by magick »

Can you post a very short program we can use to reproduce the problem you posted. If we can reproduce it we will have a patch for the problem within a day or two.
zeugman

Re: Magick++ memory leak

Post by zeugman »

Code: Select all

#include <Magick++.h>
#include <string> 
#include <iostream>
#include <fstream>
using namespace std;
using namespace Magick;

int main(){

	string test = "sdfisjfjspefosepf";
	
	Blob blob(test.c_str(),test.size());
	Image image;
    try
    {
    	image.read( blob );
    }
	catch( Exception &error_ )
    {
      cout << "Caught exception: " << error_.what() << endl;
		return EXIT_FAILURE;
    }
    return EXIT_SUCCESS;
}
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Magick++ memory leak

Post by magick »

We have a patch in ImageMagick 6.4.0-1 Beta to fix the problem you reported. The patch is available now in subversion or it is available in ftp://magick.imagemagick.org/pub/ImageMagick/beta within a few hours. Thanks.
zeugman

Re: Magick++ memory leak

Post by zeugman »

It works fine thanks
Post Reply