Possible Memory Leak when writing PNG's
Posted: 2010-08-06T01:40:59-07:00
Hi everybody,
when checking a project of mine with valgrind, I found a leak that seems to lead to ImageMagick (and possibly beyond to a png library) :
Executing following program on linux with
Program:
Results in following output:
I looked at the source of png.c but could not find anything wrong there, I think it may lie in an external library. So, basically I haven't got a clue where the problem resides.
Nevertheless, I post this in the hope that it may help an ImageMagick developer out there.
The problems only appear when writing png images, other types I have used are not affected (GIF, JPEG, TIFF).
Best Regards
Danny
when checking a project of mine with valgrind, I found a leak that seems to lead to ImageMagick (and possibly beyond to a png library) :
Executing following program on linux with
Code: Select all
valgrind --tool=memcheck --num-callers=50 ./Test
Code: Select all
#include <Magick++.h>
int main (int argc, char *argv[])
{
Magick::Image model(Magick::Geometry(100, 100), "red");
model.magick("PNG");
model.write("m.png");
return 0;
}
Code: Select all
==23124== Use of uninitialised value of size 8
==23124== at 0x7509C6B: crc32 (in /lib/libz.so.1.2.3.3)
==23124== by 0x96ED34C: ??? (in /lib/libpng12.so.0.42.0)
==23124== by 0x96F5D96: png_write_chunk (in /lib/libpng12.so.0.42.0)
==23124== by 0x96F6B21: ??? (in /lib/libpng12.so.0.42.0)
==23124== by 0x96F6F21: ??? (in /lib/libpng12.so.0.42.0)
==23124== by 0x96F7033: ??? (in /lib/libpng12.so.0.42.0)
==23124== by 0x96F73CF: ??? (in /lib/libpng12.so.0.42.0)
==23124== by 0x96FB3E8: png_write_row (in /lib/libpng12.so.0.42.0)
==23124== by 0x94DD802: ??? (in /usr/lib/ImageMagick-6.5.7/modules-Q16/coders/png.so)
==23124== by 0x94E029D: ??? (in /usr/lib/ImageMagick-6.5.7/modules-Q16/coders/png.so)
==23124== by 0x511556F: WriteImage (in /usr/lib/libMagickCore.so.2.0.1)
==23124== by 0x4E7D081: Magick::Image::write(std::string const&) (in /usr/lib/libMagick++.so.2.0.1)
==23124== by 0x400F17: main (in /home/dthomas/zorba/test/build/Test)
==23124==
==23124== Use of uninitialised value of size 8
==23124== at 0x7509C76: crc32 (in /lib/libz.so.1.2.3.3)
==23124== by 0x96ED34C: ??? (in /lib/libpng12.so.0.42.0)
==23124== by 0x96F5D96: png_write_chunk (in /lib/libpng12.so.0.42.0)
==23124== by 0x96F6B21: ??? (in /lib/libpng12.so.0.42.0)
==23124== by 0x96F6F21: ??? (in /lib/libpng12.so.0.42.0)
==23124== by 0x96F7033: ??? (in /lib/libpng12.so.0.42.0)
==23124== by 0x96F73CF: ??? (in /lib/libpng12.so.0.42.0)
==23124== by 0x96FB3E8: png_write_row (in /lib/libpng12.so.0.42.0)
==23124== by 0x94DD802: ??? (in /usr/lib/ImageMagick-6.5.7/modules-Q16/coders/png.so)
==23124== by 0x94E029D: ??? (in /usr/lib/ImageMagick-6.5.7/modules-Q16/coders/png.so)
==23124== by 0x511556F: WriteImage (in /usr/lib/libMagickCore.so.2.0.1)
==23124== by 0x4E7D081: Magick::Image::write(std::string const&) (in /usr/lib/libMagick++.so.2.0.1)
==23124== by 0x400F17: main (in /home/dthomas/zorba/test/build/Test)
==23124==
==23124== Syscall param write(buf) points to uninitialised byte(s)
==23124== at 0x5D644F0: __write_nocancel (syscall-template.S:82)
==23124== by 0x5CFF132: _IO_file_write@@GLIBC_2.2.5 (fileops.c:1276)
==23124== by 0x5D00784: _IO_do_write@@GLIBC_2.2.5 (fileops.c:530)
==23124== by 0x5CFFEBF: _IO_file_close_it@@GLIBC_2.2.5 (fileops.c:170)
==23124== by 0x5CF3AE7: fclose@@GLIBC_2.2.5 (iofclose.c:62)
==23124== by 0x50E91D5: CloseBlob (in /usr/lib/libMagickCore.so.2.0.1)
==23124== by 0x94E02A8: ??? (in /usr/lib/ImageMagick-6.5.7/modules-Q16/coders/png.so)
==23124== by 0x511556F: WriteImage (in /usr/lib/libMagickCore.so.2.0.1)
==23124== by 0x4E7D081: Magick::Image::write(std::string const&) (in /usr/lib/libMagick++.so.2.0.1)
==23124== by 0x400F17: main (in /home/dthomas/zorba/test/build/Test)
==23124== Address 0x4022165 is not stack'd, malloc'd or (recently) free'd
==23124==
==23124==
==23124== HEAP SUMMARY:
==23124== in use at exit: 344,183 bytes in 2,153 blocks
==23124== total heap usage: 2,492 allocs, 339 frees, 1,132,737 bytes allocated
==23124==
==23124== LEAK SUMMARY:
==23124== definitely lost: 0 bytes in 0 blocks
==23124== indirectly lost: 0 bytes in 0 blocks
==23124== possibly lost: 0 bytes in 0 blocks
==23124== still reachable: 344,183 bytes in 2,153 blocks
==23124== suppressed: 0 bytes in 0 blocks
==23124== Rerun with --leak-check=full to see details of leaked memory
Nevertheless, I post this in the hope that it may help an ImageMagick developer out there.
The problems only appear when writing png images, other types I have used are not affected (GIF, JPEG, TIFF).
Best Regards
Danny