Re: Memory leak
[email protected] (Brian Peschel) Wed, 26 Nov 2008 10:23:03 -0600
| Newsgroups | php.gd.devel |
|---|---|
| Message-ID | <[email protected]> |
Valgrind is also reporting a slightly different leak in the same code
==16200== 936,771 (561,456 direct, 375,315 indirect) bytes in 137 blocks
are definitely lost in loss record
742 of 744
==16200== at 0x4004864: calloc (vg_replace_malloc.c:279)
==16200== by 0xD8FA2D: xpmParseColors (in /usr/lib/libXpm.so.4.11.0)
==16200== by 0xD903F0: 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() ()
Does this help or complicate things?
- B
Brian Peschel wrote:
> 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
>
--
Brian Peschel
One Call Concepts, Inc
Systems Division
Voice: 414-259-1047 ext. 93
Fax: 414-777-3666