ImageToBlob leaks with UseEmbeddableMagick enabled

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
GiantRabbit

ImageToBlob leaks with UseEmbeddableMagick enabled

Post by GiantRabbit »

1- I had Imagemagick compiled with UseEmbeddableMagick enabled and noticed some huge memory consumption (and raising) whil blobbing...

Here is a little test proggie, compile it and drop a "test.gif" next to it.

Code: Select all

#include <iostream>
#include <iomanip>
#include <windows.h>
#include <wand/MagickWand.h>

using namespace std;

void ThrowWandException(MagickWand * wand)
   {
   ExceptionType severity;
   char* description = MagickGetException(wand, &severity);
   cerr << "Imagemagick exception: " << description << endl;
   description = (char*) MagickRelinquishMemory(description);
   exit(-1);
   }

int main(int argc, char** argv)
   {
   // Initialize magickwand
   MagickWandGenesis();
   if(MagickSetResourceLimit(MemoryResource, 3) == MagickFalse)
      {
      cerr << "Could not set memory resource limit\n";
      exit(100);
      }
   
   // Start timer
   DWORD start = GetTickCount();

   // Read, blob and destroy
   int amount = 1000;
   for(int i = 1; i < amount + 1; i++)
      {
      MagickWand * magick_wand = NewMagickWand();  

      // Read an image.
      MagickBooleanType status = MagickReadImage(magick_wand, "test.gif");
      if(status == MagickFalse)
         ThrowWandException(magick_wand);

      // Create da blob
      MagickSetImageDepth(magick_wand, 8);
      MagickSetImageFormat(magick_wand, "PNG");
      unsigned int blob_len = 0;
      unsigned char * blob = MagickGetImageBlob(magick_wand, &blob_len);
      if(blob == 0)
         ThrowWandException(magick_wand);

      // Clean up
      MagickRelinquishMemory(blob);
      magick_wand = DestroyMagickWand(magick_wand);

      // Show some stuff
      unsigned long mem_limit  = GetMagickResource(MemoryResource);
      unsigned long map_limit  = GetMagickResource(MapResource);
      unsigned long area_limit = GetMagickResource(AreaResource);
      if(i % 1 == 0.0)
         cout << "\r" << setfill(' ') << setw(5) << setprecision(1) << setiosflags(ios::fixed ) << (i == 0 ? 0 : (float)i / (float)amount * 100.0) << "% (" << mem_limit << ", " << map_limit << ", " << area_limit << ")...";

      }

   // End timing
   DWORD end = GetTickCount();
   cout << endl;
   cout << "iterations: " << amount << endl;
   cout << "time      : " << ((float)(end - start) / 1000.0) << " seconds" << endl;
   cout << "ips       : " << ((amount * 1000) / (end - start)) << " iterations per second" << endl;
   cout << endl;
   cout << "done ..." << endl;

   // Clean up
   MagickWandTerminus();
   return(0);
   }
While using -for example- MagickWriteImage this behavior does not apear.

2 - Btw. with and without UseEmbeddableMagick enabled, GetMagickResource(...) always returns 0.

BTW. compiled IM as StaticMultiThreadedDLL with

Code: Select all

#define QuantumDepth 8
#undef UseInstalledMagick
#undef ProvideDllMain
#undef HasX11
#undef UseEmbeddableMagick
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

We can reproduce the problem you posted. We have a patch in ImageMagick 6.3.0-8 Beta to fix the problem.
Post Reply