Possibly memory leak in ReadImage

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
ragesteel

Possibly memory leak in ReadImage

Post by ragesteel »

I have got memory leak after executing this code with valgrind

Code: Select all

==18171== 20 bytes in 1 blocks are still reachable in loss record 1 of 1
==18171==    at 0x4025E92: calloc (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==18171==    by 0x478A185: (within /lib/libdl-2.9.so)
==18171==    by 0x4789B80: dlopen (in /lib/libdl-2.9.so)
==18171==    by 0x45FB766: (within /usr/lib/libltdl.so.7.2.0)
==18171==    by 0x45F9764: (within /usr/lib/libltdl.so.7.2.0)
==18171==    by 0x45FA0C5: (within /usr/lib/libltdl.so.7.2.0)
==18171==    by 0x45FA8EF: lt_dlopenadvise (in /usr/lib/libltdl.so.7.2.0)
==18171==    by 0x45FAAB4: lt_dlopen (in /usr/lib/libltdl.so.7.2.0)
==18171==    by 0x41CD5EF: OpenModule (module.c:1134)
==18171==    by 0x41C90B6: GetMagickInfo (magick.c:459)
==18171==    by 0x41B70E0: SetImageInfo (image.c:3660)
==18171==    by 0x41354AC: ReadImage (constitute.c:449)
To get test image i simple executed "convert logo: test.jpg"

Operation system: openSUSE 11.1
tested ImageMagick versions: 6.5.0-5 and 6.5.3-3.

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <magick/MagickCore.h>

void initMagick(char *path) {
	char *magick_version;

	MagickBooleanType write_image_rc;

	MagickCoreGenesis(path, MagickTrue);

	magick_version = GetMagickVersion((unsigned long *) NULL);
	fprintf(stdout, "ImageMagick version: %s\n", magick_version);
}

void closeMagick() {
	MagickCoreTerminus();
}

void testReadImage() {
	ImageInfo *image_info;
	ExceptionInfo *exception_info;
	Image *image;

	image_info = CloneImageInfo((ImageInfo *) NULL);

	(void) strcpy(image_info->filename, "test.jpg");

	exception_info = AcquireExceptionInfo();

       	image = ReadImage(image_info, exception_info);

	if (UndefinedException != exception_info->severity) {
		CatchException(exception_info);
	}

	if ((Image *) NULL == image) {
		fprintf(stderr, "Unable to read image file!\n");
	} else {
		fprintf(stdout, "Image dimensions is %d×%d\n", image->columns, image->rows);
	      	image = DestroyImage(image);
	}

    	exception_info = DestroyExceptionInfo(exception_info);

	image_info = DestroyImageInfo(image_info);
}

int main(int argc, char **argv) {
	initMagick(argv[0]);

	testReadImage();

	closeMagick();

	return 0;
}
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Possibly memory leak in ReadImage

Post by magick »

The leak is in a delegate library, LTDL, not ImageMagick. Its a libtool API for dynamic loadable modules. Some libraries allow for a small amount of memory to never be freed so it may be a feature, not a bug.
Post Reply