[mapserver-commits] r8522 - branches/branch-5-2/mapserver

svn at osgeo.org svn at osgeo.org
Mon Feb 9 13:26:50 EST 2009


Author: aboudreault
Date: 2009-02-09 13:26:49 -0500 (Mon, 09 Feb 2009)
New Revision: 8522

Modified:
   branches/branch-5-2/mapserver/HISTORY.TXT
   branches/branch-5-2/mapserver/mapfile.c
Log:
Fixed memory leaks when using msUpdate*FromString methods. (#2857) 


Modified: branches/branch-5-2/mapserver/HISTORY.TXT
===================================================================
--- branches/branch-5-2/mapserver/HISTORY.TXT	2009-02-09 18:24:43 UTC (rev 8521)
+++ branches/branch-5-2/mapserver/HISTORY.TXT	2009-02-09 18:26:49 UTC (rev 8522)
@@ -13,6 +13,8 @@
 Current Version (SVN branch-5-2)
 --------------------------------
 
+- Fixed memory leaks when using msUpdate*FromString methods. (#2857) 
+
 - Fixed endianness issues with wide character strings for ArcSDE (#2878).  
   Thanks Russell McOrmond
 

Modified: branches/branch-5-2/mapserver/mapfile.c
===================================================================
--- branches/branch-5-2/mapserver/mapfile.c	2009-02-09 18:24:43 UTC (rev 8521)
+++ branches/branch-5-2/mapserver/mapfile.c	2009-02-09 18:26:49 UTC (rev 8522)
@@ -1251,6 +1251,8 @@
       if(symbol == MS_NUMBER)
 	label->angle = msyynumber;
       else if(symbol == MS_BINDING) {
+        if (label->bindings[MS_LABEL_BINDING_ANGLE].item != NULL)
+          msFree(label->bindings[MS_LABEL_BINDING_ANGLE].item);
         label->bindings[MS_LABEL_BINDING_ANGLE].item = strdup(msyytext);
         label->numbindings++;
       } else if ( symbol == MS_FOLLOW ) {
@@ -1305,8 +1307,12 @@
         return(-1);
 
       if(symbol == MS_STRING) {
+        if (label->font != NULL)
+          msFree(label->font);
         label->font = strdup(msyytext);
       } else {
+        if (label->bindings[MS_LABEL_BINDING_FONT].item != NULL)
+          msFree(label->bindings[MS_LABEL_BINDING_FONT].item);
         label->bindings[MS_LABEL_BINDING_FONT].item = strdup(msyytext);
         label->numbindings++;
       }
@@ -1367,7 +1373,9 @@
             return(-1);
         }
       } else {
-	label->bindings[MS_LABEL_BINDING_PRIORITY].item = strdup(msyytext);
+        if (label->bindings[MS_LABEL_BINDING_PRIORITY].item != NULL)
+          msFree(label->bindings[MS_LABEL_BINDING_PRIORITY].item);
+        label->bindings[MS_LABEL_BINDING_PRIORITY].item = strdup(msyytext);
         label->numbindings++;
       }
       break;
@@ -1386,6 +1394,8 @@
       if(symbol == MS_NUMBER) {
         label->size = (int) msyynumber;
       } else if(symbol == MS_BINDING) {
+        if (label->bindings[MS_LABEL_BINDING_SIZE].item != NULL)
+          msFree(label->bindings[MS_LABEL_BINDING_SIZE].item);
         label->bindings[MS_LABEL_BINDING_SIZE].item = strdup(msyytext);
         label->numbindings++;
       } else
@@ -1534,6 +1544,8 @@
 int loadExpression(expressionObj *exp)
 {
   if((exp->type = getSymbol(5, MS_STRING,MS_EXPRESSION,MS_REGEX,MS_ISTRING,MS_IREGEX)) == -1) return(-1);
+  if (exp->string != NULL)
+    msFree(exp->string);
   exp->string = strdup(msyytext);
 
   if(exp->type == MS_ISTRING)
@@ -1796,6 +1808,8 @@
       if(symbol == MS_NUMBER)
         style->angle = (double) msyynumber;
       else {
+        if (style->bindings[MS_STYLE_BINDING_ANGLE].item != NULL)
+          msFree(style->bindings[MS_STYLE_BINDING_ANGLE].item);
         style->bindings[MS_STYLE_BINDING_ANGLE].item = strdup(msyytext);
         style->numbindings++;
       }
@@ -1856,6 +1870,8 @@
       if(symbol == MS_NUMBER)
         style->size = (int) msyynumber;
       else {
+        if (style->bindings[MS_STYLE_BINDING_SIZE].item != NULL)
+          msFree(style->bindings[MS_STYLE_BINDING_SIZE].item);
 	style->bindings[MS_STYLE_BINDING_SIZE].item = strdup(msyytext);
         style->numbindings++;
       }
@@ -1867,8 +1883,14 @@
       if(symbol == MS_NUMBER)
 	style->symbol = (int) msyynumber;
       else if(symbol == MS_STRING)
-	style->symbolname = strdup(msyytext);
+      {
+        if (style->symbolname != NULL)
+          msFree(style->symbolname);
+        style->symbolname = strdup(msyytext);
+      }
       else {
+        if (style->bindings[MS_STYLE_BINDING_SYMBOL].item != NULL)
+          msFree(style->bindings[MS_STYLE_BINDING_SYMBOL].item);
         style->bindings[MS_STYLE_BINDING_SYMBOL].item = strdup(msyytext);
         style->numbindings++;
       }
@@ -2015,7 +2037,8 @@
    * to msGrowClassStyles()
    */
   class->numstyles = 0;  
-  class->maxstyles = 0;  
+  class->maxstyles = 0;
+   
   class->styles = NULL;  
 
   class->keyimage = NULL;
@@ -2287,8 +2310,12 @@
       if(state == MS_NUMBER)
 	class->styles[0]->symbol = (int) msyynumber;
       else
+      {
+        if (class->styles[0]->symbolname != NULL)
+          msFree(class->styles[0]->symbolname);
 	class->styles[0]->symbolname = strdup(msyytext);
-      class->numstyles = 1;
+        class->numstyles = 1;
+      }
       break;
 
     /*
@@ -2325,8 +2352,12 @@
       if((state = getSymbol(2, MS_NUMBER,MS_STRING)) == -1) return(-1);
       if(state == MS_NUMBER)
 	class->styles[1]->symbol = (int) msyynumber;
-      else
+      else 
+      {
+        if (class->styles[1]->symbolname != NULL)
+          msFree(class->styles[1]->symbolname);
 	class->styles[1]->symbolname = strdup(msyytext);
+      }
       class->numstyles = 2;
       break;
     default:
@@ -3135,7 +3166,11 @@
       if(state == MS_NUMBER)
 	ref->marker = (int) msyynumber;
       else
+      {
+        if (ref->markername != NULL)
+          msFree(ref->markername);
 	ref->markername = strdup(msyytext);
+      }
       break;
     case(MARKERSIZE):
       if(getInteger(&(ref->markersize)) == -1) return(-1);



More information about the mapserver-commits mailing list