Skip to content

Commit c70425d

Browse files
committed
Fix memory leaks found when running msautotest/sld tests
1 parent 14a6fb9 commit c70425d

2 files changed

Lines changed: 22 additions & 15 deletions

File tree

mapogcsld.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,7 @@ int msSLDParseOgcExpression(CPLXMLNode *psRoot, void *psObj, int binding,
14301430
exprBindings[binding].string);
14311431
expressionString = msStringConcatenate(expressionString,
14321432
operator);
1433+
msFree(exprBindings[binding].string);
14331434
msInitExpression(&(exprBindings[binding]));
14341435
status = msSLDParseOgcExpression(psRoot->psChild->psNext,
14351436
psObj, binding, objtype);
@@ -1439,6 +1440,7 @@ int msSLDParseOgcExpression(CPLXMLNode *psRoot, void *psObj, int binding,
14391440
exprBindings[binding].string);
14401441
expressionString = msStringConcatenate(expressionString,
14411442
")");
1443+
msFree(exprBindings[binding].string);
14421444
exprBindings[binding].string = expressionString;
14431445
exprBindings[binding].type = MS_EXPRESSION;
14441446
(*nexprbindings)++;

maputil.c

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,21 @@ int msScaleInBounds(double scale, double minscale, double maxscale)
7171
/*
7272
** Helper functions to convert from strings to other types or objects.
7373
*/
74-
static int bindIntegerAttribute(int *attribute, char *value)
74+
static int bindIntegerAttribute(int *attribute, const char *value)
7575
{
7676
if(!value || strlen(value) == 0) return MS_FAILURE;
7777
*attribute = MS_NINT(atof(value)); /*use atof instead of atoi as a fix for bug 2394*/
7878
return MS_SUCCESS;
7979
}
8080

81-
static int bindDoubleAttribute(double *attribute, char *value)
81+
static int bindDoubleAttribute(double *attribute, const char *value)
8282
{
8383
if(!value || strlen(value) == 0) return MS_FAILURE;
8484
*attribute = atof(value);
8585
return MS_SUCCESS;
8686
}
8787

88-
static int bindColorAttribute(colorObj *attribute, char *value)
88+
static int bindColorAttribute(colorObj *attribute, const char *value)
8989
{
9090
int len;
9191

@@ -223,15 +223,17 @@ static void bindStyle(layerObj *layer, shapeObj *shape, styleObj *style, int dra
223223
}
224224
if (style->exprBindings[MS_STYLE_BINDING_OUTLINECOLOR].type == MS_EXPRESSION)
225225
{
226-
bindColorAttribute(&style->outlinecolor,
227-
msEvalTextExpression(
228-
&(style->exprBindings[MS_STYLE_BINDING_OUTLINECOLOR]), shape));
226+
char* txt = msEvalTextExpression(
227+
&(style->exprBindings[MS_STYLE_BINDING_OUTLINECOLOR]), shape);
228+
bindColorAttribute(&style->outlinecolor, txt);
229+
msFree(txt);
229230
}
230231
if (style->exprBindings[MS_STYLE_BINDING_COLOR].type == MS_EXPRESSION)
231232
{
232-
bindColorAttribute(&style->color,
233-
msEvalTextExpression(
234-
&(style->exprBindings[MS_STYLE_BINDING_COLOR]), shape));
233+
char* txt = msEvalTextExpression(
234+
&(style->exprBindings[MS_STYLE_BINDING_COLOR]), shape);
235+
bindColorAttribute(&style->color, txt);
236+
msFree(txt);
235237
}
236238
}
237239
if(style->opacity < 100 || style->color.alpha != 255 ) {
@@ -342,15 +344,17 @@ static void bindLabel(layerObj *layer, shapeObj *shape, labelObj *label, int dra
342344
}
343345
if (label->exprBindings[MS_LABEL_BINDING_COLOR].type == MS_EXPRESSION)
344346
{
345-
bindColorAttribute(&label->color,
346-
msEvalTextExpression(
347-
&(label->exprBindings[MS_LABEL_BINDING_COLOR]), shape));
347+
char* txt = msEvalTextExpression(
348+
&(label->exprBindings[MS_LABEL_BINDING_COLOR]), shape);
349+
bindColorAttribute(&label->color, txt);
350+
msFree(txt);
348351
}
349352
if (label->exprBindings[MS_LABEL_BINDING_OUTLINECOLOR].type == MS_EXPRESSION)
350353
{
351-
bindColorAttribute(&label->outlinecolor,
352-
msEvalTextExpression(
353-
&(label->exprBindings[MS_LABEL_BINDING_OUTLINECOLOR]), shape));
354+
char* txt = msEvalTextExpression(
355+
&(label->exprBindings[MS_LABEL_BINDING_OUTLINECOLOR]), shape);
356+
bindColorAttribute(&label->outlinecolor, txt);
357+
msFree(txt);
354358
}
355359
}
356360
}
@@ -785,6 +789,7 @@ double msEvalDoubleExpression(expressionObj *expression, shapeObj *shape)
785789
value = 0.0;
786790
} else {
787791
value = atof(p.result.strval);
792+
msFree(p.result.strval);
788793
}
789794
return value;
790795
}

0 commit comments

Comments
 (0)