[mapserver-dev] Memory Leak

Ned Harding nharding at extendthereach.com
Fri Oct 3 17:02:24 EDT 2008


There is a memory leak in msInsertLayer.  The below patch fixes it.  Can
someone else review it and tell me what I should do with it?  

 

Thanks,

 

Ned.

 

Index: S:/3rdParty/GIS/MapServer/mapobject.c

===================================================================

--- S:/3rdParty/GIS/MapServer/mapobject.c       (revision 15750)

+++ S:/3rdParty/GIS/MapServer/mapobject.c     (working copy)

@@ -498,10 +498,20 @@

     }

 

     /* Ensure there is room for a new layer */

-    if (msGrowMapLayers(map) == NULL)

-        return -1;

-    /* Catch attempt to insert past end of layers array */

-    else if (nIndex >= map->numlayers) {

+    if (map->numlayers == map->maxlayers)

+              {

+                              if (msGrowMapLayers(map) == NULL)

+                                              return -1;

+              }

+

+              /* msGrowMapLayers allocates the new layer which we don't
need to do since we have 1 that we are inserting 

+                              not sure if it is possible for this to be
non null otherwise, but better to check since this function

+                              replaces the value */

+              if (map->layers[map->numlayers]!=NULL)

+                              free(map->layers[map->numlayers]);

+

+              /* Catch attempt to insert past end of layers array */

+              if (nIndex >= map->numlayers) {

         msSetError(MS_CHILDERR, "Cannot insert layer beyond index %d",

                    "msInsertLayer()", map->numlayers-1);

         return -1;

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapserver-dev/attachments/20081003/b28acce6/attachment.html


More information about the mapserver-dev mailing list