[MAPSERVER-USERS] Antwort: Re: leaking memory in java mapscript (was Re: thread safety)

Tamas Szekeres szekerest at gmail.com
Fri Feb 22 07:01:04 EST 2008


2008/2/22, rich.fromm <nospam420 at yahoo.com>:
>
> The actual memory allocation happens in gdImageCreate() in gd.c, which
>  returns
>  gdImagePtr im.
>
>  This sets gdImagePtr img in msImageCreateWithPaletteGD() in mapgd.c, which
>  returns it.
>
>  This then sets gdImagePtr gdPImg in msSaveImageBufferGD() in mapgd.c.  This
>  value is NOT directly returned.  Instead, it is used to set unsigned char
>  *imgbytes, and that is returned.
>
>

I think this might be the case. Would you try adding something like:

Index: mapgd.c
===================================================================
--- mapgd.c	(revision 7383)
+++ mapgd.c	(working copy)
@@ -3686,6 +3686,8 @@
       gdPImg = msImageCreateWithPaletteGD(img, palette,
gdImageSX(img), gdImageSY(img));
       msImageCopyForcePaletteGD(img, gdPImg, method);
       imgbytes = gdImagePngPtr(gdPImg, size_ptr);
+      if (gdPImg)
+        gdImageDestroy(gdPImg);
     }
     else if ( force_pc256 ) {
       gdImagePtr gdPImg;
@@ -3704,6 +3706,8 @@
       for( i = 0; i < gdPImg->colorsTotal; i++ )
         gdPImg->open[i] = 0;
       imgbytes = gdImagePngPtr(gdPImg, size_ptr);
+      if (gdPImg)
+        gdImageDestroy(gdPImg);
     }
     else
       imgbytes = gdImagePngPtr(img, size_ptr);


If this fix is helpful then attach it to the ticket please.

Best regards,

Tamas


More information about the mapserver-users mailing list