I suspect I'm doing something wrong but I can't find it.

This very simple code has a memory leak reported. When I uncomment the stuff
that does the drawing I get an image but the memory leak gets worse.

Any help would be appreciated!

-Leonard



/* Bring in ImageMagick library functions */
#include "MagickWand.h"

#include <mcheck.h>

unsigned char *bitmap;

int main(int argc,char **argv)
{

  char buffer[50];
  int size=400;
  int picrad=200;


#define ThrowWandException(wand)  \
  {      \
    char     \
      *description;    \
          \
    ExceptionType    \
      severity;     \
           \
    description=MagickGetException(wand,&severity);   \
    (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \
    description=(char *) MagickRelinquishMemory(description);  \
    exit(-1);        \
  }

  MagickBooleanType
    status;

  MagickWand
    *my_image;

  DrawingWand
    *d_wand;

  PixelWand
    *p_wand;

mtrace();


  /* Get ready to use ImageMagick */
  MagickWandGenesis();

  bitmap = (unsigned char *)malloc(size*size*3*sizeof(char));
 /* Make a new image */
  my_image=NewMagickWand();

  /* Tell ImageMagick that image is a set of pixels in memory*/
  status=MagickConstituteImage(my_image,size,size,"RGB",CharPixel,bitmap);
  if (status == MagickFalse)
    ThrowWandException(my_image);
//  MagickSetCompressionQuality(my_image,100);

//  d_wand=NewDrawingWand();
//  p_wand=NewPixelWand();
//  PixelSetColor(p_wand,"white");
//   DrawSetFillColor(d_wand,p_wand);
//  DrawSetFont(d_wand,"Helios");
//  DrawSetFontSize(d_wand,picrad/20);
//  sprintf(buffer,"Mag: %le",1.7320508);
//  DrawAnnotation(d_wand,(double)picrad/50,(double)size-picrad/50,(const
unsigned char *)buffer);

//  MagickDrawImage(my_image,d_wand);
//  DestroyPixelWand(p_wand);
//  DestroyDrawingWand(d_wand);

  /* Write the image then destroy it.*/

  status=MagickWriteImage(my_image,"test.png");
  if (status == MagickFalse)
    ThrowWandException(my_image);
  my_image=DestroyMagickWand(my_image);

  MagickWandTerminus();

free(bitmap);

}





_______________________________________________
Magick-users mailing list
[email protected]
http://studio.imagemagick.org/mailman/listinfo/magick-users

Reply via email to