Possible Memory Leak when writing PNG's

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
dannyjames

Possible Memory Leak when writing PNG's

Post by dannyjames »

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

Code: Select all

valgrind --tool=memcheck --num-callers=50 ./Test  
Program:

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;
}
Results in following output:

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
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
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Possible Memory Leak when writing PNG's

Post by glennrp »

Does the memory leak still exist when you build with the current
versions of libpng (1.2.44 or preferably 1.4.3) and zlib (1.2.5)?

Glenn
dannyjames

Re: Possible Memory Leak when writing PNG's

Post by dannyjames »

Hi,

Current versions:

libpng 1.2.42
zlib 1.2.3.3

As it is a remote machine, I will first have to check with somebody who has got the appropriate rights to update the libraries and then come back to you with new results.

Regards

Danny
Post Reply