[mapserver-dev] 5.2.0 memory leaks?

Stephen Woodbridge woodbri at swoodbridge.com
Mon Jul 14 20:08:18 EDT 2008


Steve,

This patch looks like it might fix the leak below. I will also make a 
ticket for it and attach the patch. I does solve the problem I was 
experiencing, but I'm not sure if this is complete or even the correct 
way to do this.

-Steve W


woodbri at carto:~/work/precache3/mapserver-5.2.0-rc1$ diff -uN 
maplayer.c-orig maplayer.c
--- maplayer.c-orig     2008-02-28 19:02:49.000000000 -0500
+++ maplayer.c  2008-07-14 18:57:18.000000000 -0400
@@ -171,6 +171,7 @@
  */
  void msLayerClose(layerObj *layer)
  {
+  int i;
    /* no need for items once the layer is closed */
    msLayerFreeItemInfo(layer);
    if(layer->items) {
@@ -178,6 +179,18 @@
      layer->items = NULL;
      layer->numitems = 0;
    }
+  for (i=0; i<layer->numclasses; i++) {
+    if ( layer->class[i]->expression.items ) {
+      msFreeCharArray(layer->class[i]->expression.items, 
layer->class[i]->expression.numitems);
+      layer->class[i]->expression.items = NULL;
+      layer->class[i]->expression.numitems = 0;
+    }
+    if ( layer->class[i]->expression.indexes ) {
+      msFree(layer->class[i]->expression.indexes);
+      layer->class[i]->expression.indexes = NULL;
+    }
+  }
+

    if (layer->vtable) {
      layer->vtable->LayerClose(layer);



Stephen Woodbridge wrote:
> Steve,
> 
> FYI, I just downloaded gd-2.0.36RC1.tar.gz and this leak appears to be 
> fixed in this new code.  So the only leaks left would be mapserver leaks:
> 
> ==26531==
> ==26531== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 3 from 1)
> ==26531== malloc/free: in use at exit: 90 bytes in 9 blocks.
> ==26531== malloc/free: 294,249 allocs, 294,240 frees, 269,637,193 bytes 
> allocated.
> ==26531== For counts of detected errors, rerun with: -v
> ==26531== searching for pointers to 9 not-freed blocks.
> ==26531== checked 6,932,464 bytes.
> ==26531==
> ==26531== 24 bytes in 3 blocks are definitely lost in loss record 2 of 3
> ==26531==    at 0x4A18DA3: malloc (vg_replace_malloc.c:149)
> ==26531==    by 0x420F21: msLayerWhichItems (maplayer.c:440)
> ==26531==    by 0x423A8D: msDrawVectorLayer (mapdraw.c:841)
> ==26531==    by 0x4236C4: msDrawLayer (mapdraw.c:738)
> ==26531==    by 0x4232F3: msDrawMap (mapdraw.c:441)
> ==26531==    by 0x40A818: main (genimages.c:1148)
> ==26531==
> ==26531==
> ==26531== 66 (48 direct, 18 indirect) bytes in 3 blocks are definitely 
> lost in loss record 3 of 3
> ==26531==    at 0x4A1A362: calloc (vg_replace_malloc.c:279)
> ==26531==    by 0x420F00: msLayerWhichItems (maplayer.c:435)
> ==26531==    by 0x423A8D: msDrawVectorLayer (mapdraw.c:841)
> ==26531==    by 0x4236C4: msDrawLayer (mapdraw.c:738)
> ==26531==    by 0x4232F3: msDrawMap (mapdraw.c:441)
> ==26531==    by 0x40A818: main (genimages.c:1148)
> ==26531==
> ==26531== LEAK SUMMARY:
> ==26531==    definitely lost: 72 bytes in 6 blocks.
> ==26531==    indirectly lost: 18 bytes in 3 blocks.
> ==26531==      possibly lost: 0 bytes in 0 blocks.
> ==26531==    still reachable: 0 bytes in 0 blocks.
> ==26531==         suppressed: 0 bytes in 0 blocks.
> ==26531== Reachable blocks (those to which a pointer was found) are not 
> shown.
> ==26531== To see them, rerun with: --show-reachable=yes
> 
> -Steve W
> 
> Steve Lime wrote:
>> Have run against 5.0? If they're there in that version too then I'm 
>> not worried about
>> this for this release. My guess is that these are not new leaks.
>>
>> Steve
>>
>>>>> On 7/13/2008 at 12:13 AM, in message 
>>>>> <48798F14.1070801 at swoodbridge.com>,
>> Stephen Woodbridge <woodbri at swoodbridge.com> wrote:
>>> Steve L,
>>>
>>> I have been playing around with a test program to generate some 
>>> images. It was some mapscript that I wanted to see if I could get 
>>> working as a C program calling the mapserver library calls.
>>>
>>> This run was based on mapserver-5.2.0-beta2 and it looks like we have 
>>> some memory leaks in the mapserver code. It is also possible that I 
>>> mis-used the library, but these seem to be pretty deep in mapserver 
>>> and I'm not trying to do anything fancy.
>>>
>>> I'll check the same run against RC1, but I guess my generic question 
>>> is how much check has been done with valgrind. This run only 
>>> generates two images, but if I wanted to generate lots more this 
>>> could be serious. In fact, I think I've seen php/mapscript 
>>> precache2.php run into a leak where the process kept growing and 
>>> finally died and had to be restarted.
>>>
>>> -Steve
>>>
>>>
>>> ==5821== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 3 from 1)
>>> ==5821== malloc/free: in use at exit: 7,724 bytes in 29 blocks.
>>> ==5821== malloc/free: 337,243 allocs, 337,214 frees, 121,668,226 
>>> bytes allocated.
>>> ==5821== For counts of detected errors, rerun with: -v
>>> ==5821== searching for pointers to 29 not-freed blocks.
>>> ==5821== checked 15,450,752 bytes.
>>> ==5821==
>>> ==5821== 24 bytes in 3 blocks are definitely lost in loss record 5 of 15
>>> ==5821==    at 0x4A18DA3: malloc (vg_replace_malloc.c:149)
>>> ==5821==    by 0x4276A1: msLayerWhichItems (maplayer.c:440)
>>> ==5821==    by 0x42A20D: msDrawVectorLayer (mapdraw.c:841)
>>> ==5821==    by 0x429E44: msDrawLayer (mapdraw.c:738)
>>> ==5821==    by 0x429A73: msDrawMap (mapdraw.c:441)
>>> ==5821==    by 0x40E67E: main (genimages.c:1112)
>>> ==5821==
>>> ==5821==
>>> ==5821== 24 bytes in 4 blocks are definitely lost in loss record 6 of 15
>>> ==5821==    at 0x4A18DA3: malloc (vg_replace_malloc.c:149)
>>> ==5821==    by 0x4B35D78: gdMalloc (in /usr/lib/libgd.so.2.0.33)
>>> ==5821==    by 0x4B33830: (within /usr/lib/libgd.so.2.0.33)
>>> ==5821==    by 0x4B336DB: gdImageCreatePaletteFromTrueColor (in 
>>> /usr/lib/libgd.so.2.0.33)
>>> ==5821==    by 0x43ACED: msImageCreateWithPaletteGD (mapgd.c:3441)
>>> ==5821==    by 0x43B022: msSaveImageGDCtx (mapgd.c:3576)
>>> ==5821==    by 0x43AE2F: msSaveImageGD (mapgd.c:3495)
>>> ==5821==    by 0x4437A8: msSaveImageAGG (mapagg.cpp:2216)
>>> ==5821==    by 0x41ACB4: msSaveImage (maputil.c:657)
>>> ==5821==    by 0x40E6B4: main (genimages.c:1120)
>>> ==5821==
>>> ==5821==
>>> ==5821== 66 (48 direct, 18 indirect) bytes in 3 blocks are definitely 
>>> lost in loss record 11 of 15
>>> ==5821==    at 0x4A1A362: calloc (vg_replace_malloc.c:279)
>>> ==5821==    by 0x427680: msLayerWhichItems (maplayer.c:435)
>>> ==5821==    by 0x42A20D: msDrawVectorLayer (mapdraw.c:841)
>>> ==5821==    by 0x429E44: msDrawLayer (mapdraw.c:738)
>>> ==5821==    by 0x429A73: msDrawMap (mapdraw.c:441)
>>> ==5821==    by 0x40E67E: main (genimages.c:1112)
>>> ==5821==
>>> ==5821== LEAK SUMMARY:
>>> ==5821==    definitely lost: 96 bytes in 10 blocks.
>>> ==5821==    indirectly lost: 18 bytes in 3 blocks.
>>> ==5821==      possibly lost: 0 bytes in 0 blocks.
>>> ==5821==    still reachable: 7,610 bytes in 16 blocks.
>>> ==5821==         suppressed: 0 bytes in 0 blocks.
>>> ==5821== Reachable blocks (those to which a pointer was found) are 
>>> not shown.
>>> ==5821== To see them, rerun with: --show-reachable=yes
>>>
>>> _______________________________________________
>>> mapserver-dev mailing list
>>> mapserver-dev at lists.osgeo.org 
>>> http://lists.osgeo.org/mailman/listinfo/mapserver-dev
>>
> 
> _______________________________________________
> mapserver-dev mailing list
> mapserver-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapserver-dev



More information about the mapserver-dev mailing list