Opened 13 years ago

Last modified 13 years ago

#3831 new defect

memory leaks in graticule layer

Reported by: tbonfort Owned by: sdlime
Priority: normal Milestone: 6.0 release
Component: MapServer C Library Version: svn-trunk (development)
Severity: normal Keywords:
Cc:

Description

valgrind reports 3 distinct memory leaks for graticule layers:

==16155== 3 bytes in 1 blocks are definitely lost in loss record 1 of 5
==16155==    at 0x4C2815C: malloc (vg_replace_malloc.c:236)
==16155==    by 0xBDACB81: strdup (strdup.c:43)
==16155==    by 0x445919: msStrdup (mapstring.c:2117)
==16155==    by 0x448753: loadGrid (mapfile.c:973)
==16155==    by 0x45224D: loadLayer (mapfile.c:3676)
==16155==    by 0x459A9F: loadMapInternal (mapfile.c:5388)
==16155==    by 0x45A5CC: msLoadMap (mapfile.c:5653)
==16155==    by 0x441B0A: main (shp2img.c:129)
==16090== 4,112 bytes in 1 blocks are indirectly lost in loss record 6 of 7
==16090==    at 0x4C2815C: malloc (vg_replace_malloc.c:236)
==16090==    by 0x461E61: msSmallMalloc (maputil.c:2152)
==16090==    by 0x4A2FAF: msGraticuleLayerNextShape (mapgraticule.c:453)
==16090==    by 0x484D23: msLayerNextShape (maplayer.c:164)
==16090==    by 0x48AE84: msDrawVectorLayer (mapdraw.c:843)
==16090==    by 0x48A010: msDrawLayer (mapdraw.c:730)
==16090==    by 0x489193: msDrawMap (mapdraw.c:422)
==16090==    by 0x44255E: main (shp2img.c:299)
==16090== 
==16090== 4,128 (16 direct, 4,112 indirect) bytes in 1 blocks are definitely lost in loss record 7 of 7
==16090==    at 0x4C2815C: malloc (vg_replace_malloc.c:236)
==16090==    by 0x461E61: msSmallMalloc (maputil.c:2152)
==16090==    by 0x4A2571: msGraticuleLayerNextShape (mapgraticule.c:299)
==16090==    by 0x484D23: msLayerNextShape (maplayer.c:164)
==16090==    by 0x48AE84: msDrawVectorLayer (mapdraw.c:843)
==16090==    by 0x48A010: msDrawLayer (mapdraw.c:730)
==16090==    by 0x489193: msDrawMap (mapdraw.c:422)
==16090==    by 0x44255E: main (shp2img.c:299)

and

==14776== 184 bytes in 1 blocks are definitely lost in loss record 6 of 8
==14776==    at 0x4C2815C: malloc (vg_replace_malloc.c:236)
==14776==    by 0x4521D6: loadLayer (mapfile.c:3672)
==14776==    by 0x459A82: loadMapInternal (mapfile.c:5387)
==14776==    by 0x45A5AF: msLoadMap (mapfile.c:5652)
==14776==    by 0x441B0A: main (shp2img.c:129)

Attached is a patch for the last two, I don't understand where the first one is coming from, it's when strduping DD:

    case( LABELFORMAT ):
      if(getString(&((graticuleObj *)pLayer->layerinfo)->labelformat) == MS_FAILURE) {
	if(strcasecmp(msyystring_buffer, "DD") == 0) /* DD triggers a symbol to be returned instead of a string so check for this special case */
	  ((graticuleObj *)pLayer->layerinfo)->labelformat = msStrdup("DD");

not sure who I should assign this bug to as the graticule maintainer isn't active anymore

Change History (4)

comment:1 by tbonfort, 13 years ago

the patch for the last two leaks:

Index: mapgraticule.c
===================================================================
--- mapgraticule.c	(revision 11542)
+++ mapgraticule.c	(working copy)
@@ -143,6 +143,9 @@
     pInfo->pboundinglines = NULL;
   }
 
+  free(layer->layerinfo);
+  layer->layerinfo=NULL;
+
   return MS_SUCCESS;
 }
 
@@ -477,8 +480,11 @@
       pInfo->bvertical   = 0;
   }
 
-  if (pInfo->dwhichlatitude >  pInfo->dendlatitude)
+  if (pInfo->dwhichlatitude >  pInfo->dendlatitude) {
+    /* free the lineObj and pointObj that have been erroneously allocated beforehand */
+    msFreeShape(shape);
     return MS_DONE;
+  }
 
   return MS_SUCCESS;
 }

comment:2 by sdlime, 13 years ago

I'll have a look... Steve

comment:3 by sdlime, 13 years ago

I applied your patch in r11565. Do you have the mapfile you were using to generate the leaks? -Steve

comment:4 by tbonfort, 13 years ago

it's in msautotest/renderers/grid.map

Note: See TracTickets for help on using tickets.