Memory leak in DeleteMagickRegistry in 6.3.1

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

Memory leak in DeleteMagickRegistry in 6.3.1

Post by rmagick »

A user has reported a memory leak in RMagick that occurs in the DeleteMagickRegistry method when RMagick is built with ImageMagick 6.3.1. With 6.3.1, RMagick uses SetMagickRegistry to register an image, then later calls DeleteMagickRegistry to delete the registered image. Here are the relevant calls:

long registry_id;
registry_id = SetMagickRegistry(ImageRegistryType, image, sizeof(Image), &image->exception);

(void) DeleteMagickRegistry(registry_id);

However, DeleteMagickRegistry never actually releases the registered copy of the image. Using gdb, I tracked the call into GetValueFromSplayTree. At line 614, the splay_tree->compare field is NULL, so GetValueFromSplayTree jumps to line 617, where it compares the splay_info->root->key with a pointer to the key, which is registry_id in my code. Since key is just a pointer to a long on the stack, I don't see how this can ever work, so either DeleteMagickRegistry has a bug or I'm using Set/DeleteMagickRegistry incorrectly.

When RMagick is built with 6.3.4 or later, I use the new Set/DeleteImageRegistry methods and there is no memory leak.

RMagick still tries to support 6.0.0 and later, so it would be nice if there was a way to change RMagick to work with Set/DeleteMagickRegistry. Can you recommend a change, or should I ask the user to upgrade to 6.3.4 or later?

Please let me know if you need any more information. Thanks for your help!
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Memory leak in DeleteMagickRegistry in 6.3.1

Post by magick »

Delete/SetMagickRegistery() was written very early in the development of ImageMagick and had a few design flaws (such as the memory leak you reported). We implemented Set/DeleteImageRegistry() to fix the design problem and memory leak. Our recommendation is for your RMagick users to upgrade if possible. We could apply a patch to previous versions of ImageMagick but its unlikely the various repositories will adopt the patch and issue updated releases (e.g. Debian, Fedora, Ubuntu, etc).
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

Re: Memory leak in DeleteMagickRegistry in 6.3.1

Post by rmagick »

I'll recommend an upgrade. Thanks!
Post Reply