Memory Leak in Magick::Image::profile

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
egb
Posts: 1
Joined: 2012-08-22T01:00:11-07:00
Authentication code: 67789

Memory Leak in Magick::Image::profile

Post by egb »

Hello,

I'm seeing a 65541-Byte memory leak every time a call to "Magick::Image::profile(std::string) const" doesn't find the profile specified in the image.

(Version 6.6.9.7, ubuntu 12.04 package)

Example code to repoduce:

Code: Select all

#include <Magick++.h>
#include <iostream>

int main(int argc, const char * argv[]) {
  Magick::Image img(argv[1]);
  std::cout<<"Image loaded ("<<img.columns()<<"x"<<img.rows()<<")"<<std::endl;

  Magick::Blob blob;
  try { 
    blob = img.profile("8BIM"); 
  }  catch(const Magick::Exception & e) {
    std::cerr << "ME: " << e.what() << std::endl; 
  } catch (...) {
    std::cerr << "unknown exception" << std::endl; 
  }
  std::cout << "data: "<< blob.length()<<std::endl;

  return 0;

}
Called with an Jpg containing 8BIM/IPTC, the output is:
Image loaded (115x158)
data: 738

and no leaked memory.

Called with a plain jpeg without 8Bim, the output is:
Image loaded (115x158)
ME: Magick: no 8BIM data is available `' @ error/meta.c/WriteMETAImage/2269
data: 0

and the application leaks ~64KiB.

valgrind says:

==31033== 65,541 bytes in 1 blocks are possibly lost in loss record 34,205 of 34,392
==31033== at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==31033== by 0x4E1E505: AcquireMagickMemory (in /usr/lib/libMagickCore.so.4.0.1)
==31033== by 0x4E1E54C: AcquireQuantumMemory (in /usr/lib/libMagickCore.so.4.0.1)
==31033== by 0x4D3AFED: ImageToBlob (in /usr/lib/libMagickCore.so.4.0.1)
==31033== by 0x49834B7: Magick::Image::write(Magick::Blob*, std::string const&) (in /usr/lib/libMagick++.so.4.0.1)
==31033== by 0x49835C3: Magick::Image::profile(std::string) const (in /usr/lib/libMagick++.so.4.0.1)


My first guess would be a problem with exception handling inside Image::write, called on the temporary image copy created by Image::profile.

Any ideas for a quick workaround? Is there a way to check in advance if a 8BIM-profile exists, so no exception is thrown?

Thanks,
Ernst
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Memory Leak in Magick::Image::profile

Post by magick »

We can reproduce the problem you posted and have a patch. Look for it in ImageMagick 6.7.9-1 Beta by sometime tomorrow. Thanks.
Post Reply