crash in Imagmagick : what am I doing wrong?

"Jouk Jansen" <[email protected]> Mon, 10 Oct 2011 09:17:40 +0200 (MEST)
Newsgroups gmane.comp.video.image-magick.user
Message-ID <[email protected]>
Hi All,

I'm running a program linked against ImageMagick SVN version 5365. However I
see some crashes in the routine below. The routine is designed to receive a
pixel map in pic_ and write that to an image file ins some format with the
specified filename. If I call the routine once it works OK. But now I'm
calling it many times with different filenames and pixelmaps. After 80 to 90
written files the routine stops writing the files, hangs a long time and
eventually crashes. In my home directory I find a rather large file called
python_tmpmagick-<random characters>.
It looks like some data is not reset properly. What did I forget to
deallocate/destroy?

                      Jouk


>>>>>>>Code start<<<<<<<

#include <stdio.h>

#include <stdlib.h>

#include <memory.h>

#include <math.h>

#include <time.h>

#include <sys/types.h>

#include <stdarg.h>

#include <magick/api.h>

void
  magick_write( char* filename , int* pic_ , int w_ , int h_ , char*
		       graph_type , int quality )
{
   Image* imageData = (Image*) NULL;
   ImageInfo imageInfo;
   Quantum* pixels;
   ExceptionInfo exception;
   int i;

   GetImageInfo( &imageInfo );
   GetExceptionInfo( &exception );
   imageInfo.dither = 0;
   imageInfo.quality = quality;
   imageInfo.colorspace = RGBColorspace;
   imageData=AcquireImage( &imageInfo );
   imageData->depth=8;
   imageData->columns = w_;
   imageData->rows = h_;
   imageData->colors = 256;
   imageData->matte = 0;
   imageData->units=PixelsPerInchResolution;
   imageData->x_resolution = imageData->y_resolution = 300;
   imageData->page.width = 595;
   imageData->page.height = 842;
   imageData->page.x = imageData->page.y = 0;
   AcquireImageColormap(imageData,imageData->colors , &exception );
   imageData->storage_class = DirectClass;
   pixels = GetAuthenticPixels( imageData , 0 , 0 , w_ , h_ , &exception );
   for ( i=0; i < h_ * w_ ; i++ , pic_++ )
     {
	SetPixelRed( imageData , imageData->colormap[ *pic_ ].red , pixels );
	SetPixelGreen( imageData , imageData->colormap[ *pic_ ].green , pixels
		     );
	SetPixelBlue( imageData , imageData->colormap[ *pic_ ].blue , pixels );
	pixels += GetPixelChannels( imageData );
     }
   SyncAuthenticPixels( imageData , &exception );
   strcpy( imageData->magick, graph_type );
   strcpy( imageData->filename, filename );
   imageData->delay = 10;
   WriteImage ( &imageInfo, imageData , &exception );
   DestroyImage( imageData );
   DestroyImageInfo( &imageInfo );
   DestroyExceptionInfo( &exception );
}

>>>>>>>Code end<<<<<<<



Pax, vel iniusta, utilior est quam iustissimum bellum.
    (free after Marcus Tullius Cicero (106 b.Chr.-46 b.Chr.)
     Epistularum ad Atticum 7.1.4.3)

>------------------------------------------------------------------------------<

  Jouk Jansen
		 
  [email protected]

  Technische Universiteit Delft        tttttttttt  uu     uu  ddddddd
  Kavli Institute of Nanoscience       tttttttttt  uu     uu  dd    dd
  Nationaal centrum voor HREM              tt      uu     uu  dd     dd
  Lorentzweg 1                             tt      uu     uu  dd     dd
  2628 CJ Delft                            tt      uu     uu  dd     dd
  Nederland                                tt      uu     uu  dd    dd
  tel. 31-15-2782272                       tt       uuuuuuu   ddddddd

>------------------------------------------------------------------------------<