Memory leak in BlobToImage

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
kiryushinm
Posts: 3
Joined: 2015-12-17T02:25:38-07:00
Authentication code: 1151

Memory leak in BlobToImage

Post by kiryushinm » 2015-12-17T04:09:12-07:00

Hi!

I'm using IM 6.9.2-6 on Linux for convertion images to png format.
I've got a problem with very specific type of image - multisize ICO (for example livejournal.com/favicon.ico)

The convertion works fine on them but it seems like there is a memory leak. I prepared very simple code which illustrates this case:

Code: Select all

int main(int, const char *argv[]) {
    ifstream fin(argv[1], ios::binary);
    ostringstream ostrm;
    ostrm << fin.rdbuf();
    string from(ostrm.str());
    
    while (true) {
        _ImageInfo* imageInfoPtr(CloneImageInfo(0));
        strcpy(imageInfoPtr->magick, "ICO");
       
        ExceptionInfo* _exception = AcquireExceptionInfo();
        _Image *imagePtr = BlobToImage(imageInfoPtr, from.c_str(), from.length(), _exception);
        DestroyImage(imagePtr);
        DestroyImageInfo(imageInfoPtr);
        DestroyExceptionInfo(_exception);
    }
Infinite loop here causes a huge memory consumption on multisize ICO file. But if I try any other image format it works fine.

kiryushinm
Posts: 3
Joined: 2015-12-17T02:25:38-07:00
Authentication code: 1151

Re: Memory leak in BlobToImage

Post by kiryushinm » 2015-12-17T06:13:49-07:00

The problem is in coders/icon.c, ReadICONImage function
There is a loop iterating through all images in ico file. After each iteration it allocates memory for the next one. But it seems like this memory stays allocated.

kiryushinm
Posts: 3
Joined: 2015-12-17T02:25:38-07:00
Authentication code: 1151

Re: Memory leak in BlobToImage

Post by kiryushinm » 2015-12-17T06:44:53-07:00

Got it.

I should've used DestroyImageList instead of DestroyImage

User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Memory leak in BlobToImage

Post by dlemstra » 2015-12-17T07:57:49-07:00

Feel free to submit a pull requests here: https://github.com/ImageMagick/ImageMagick. We can also do the patch if you prefer that.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

Post Reply