Memory leak
[email protected] (Brian Peschel) Wed, 26 Nov 2008 10:18:16 -0600
| Newsgroups | php.gd.devel |
|---|---|
| Message-ID | <[email protected]> |
I have a very simple routine to get the height and width of an XPM image:
void XpmImageConverter::getImageDimensions()
{
gdImagePtr image;
char tmpFilename[_fname.length() + 1];
// GD doesn't like const pointers :(
strcpy(tmpFilename, _fname.c_str());
if ((image = gdImageCreateFromXpm(tmpFilename)) == NULL)
{
std::cerr << "Failed to open jpeg file \"" << _fname << "\"" <<
std::endl;
return;
}
imageWidth = gdImageSX(image);
imageHeight = gdImageSY(image);
gdImageDestroy(image);
}
where imageWidth and imageHeight are unsigned int (class variable) and
_fname is a std::string (class variable).
According to Valgrind, this is leaking a lot of memory (for small
images, largest is 48x48 pixels, most are 24x24 pixels):
==16200== 32,731,968 bytes in 33 blocks are possibly lost in loss record
744 of 744
==16200== at 0x4005525: malloc (vg_replace_malloc.c:149)
==16200== by 0xD9067A: xpmParseData (in /usr/lib/libXpm.so.4.11.0)
==16200== by 0xD893B9: XpmReadFileToXpmImage (in
/usr/lib/libXpm.so.4.11.0)
==16200== by 0x80CBED5: gdImageCreateFromXpm (in )
==16200== by 0x437E45F: XpmImageConverter::getImageDimensions() ()
This is on Fedora 8, gcc 4.1.2-33, gd 2.0.35, and libXpm 3.5.7.
Any ideas? Restarting my app to free up the memory is kind of a pain.
- Brian