Skip to content
Permalink
Browse files

Fix various memory leaks found when running msautotest

  • Loading branch information...
rouault committed Sep 5, 2019
1 parent c49a14d commit d7b11f3adb3cf44035d09124300fdd7162a184a2
Showing with 313 additions and 184 deletions.
  1. +3 −1 mapcopy.c
  2. +2 −0 mapfile.c
  3. +4 −1 maplabel.c
  4. +1 −1 maplayer.c
  5. +167 −122 mapmetadata.c
  6. +7 −4 mapogcsld.c
  7. +5 −5 mapogcsld.h
  8. +24 −9 mapogcsos.c
  9. +16 −1 mapogroutput.c
  10. +5 −1 mapows.c
  11. +1 −0 mapquery.c
  12. +10 −4 mapresample.c
  13. +5 −2 mapsymbol.c
  14. +16 −4 mapwcs.c
  15. +13 −9 mapwcs20.c
  16. +1 −0 mapwfs.c
  17. +10 −0 mapwms.c
  18. +23 −20 mapwmslayer.c
@@ -204,10 +204,12 @@ int msCopyFontSet(fontSetObj *dst, fontSetObj *src, mapObj *map)

int msCopyExpression(expressionObj *dst, expressionObj *src)
{
if((dst->type == MS_REGEX) && dst->compiled) ms_regfree(&(dst->regex));
dst->compiled = MS_FALSE;

MS_COPYSTRING(dst->string, src->string);
MS_COPYSTELEM(type);
MS_COPYSTELEM(flags);
dst->compiled = MS_FALSE;

return MS_SUCCESS;
}
@@ -6512,6 +6512,7 @@ static int loadMapInternal(mapObj *map)
if(getInteger(&(map->imagequality)) == -1) return MS_FAILURE;
break;
case(IMAGETYPE):
msFree(map->imagetype);
map->imagetype = getToken();
break;
case(INTERLACE):
@@ -6879,6 +6880,7 @@ int msUpdateMapFromURL(mapObj *map, char *variable, char *string)

/* TODO: should validate or does msPostMapParseOutputFormatSetup() do enough? */

msFree(map->imagetype);
map->imagetype = getToken();
msPostMapParseOutputFormatSetup( map );
break;
@@ -251,8 +251,11 @@ int msAddLabelGroup(mapObj *map, imageObj *image, layerObj* layer, int classinde
msPopulateTextSymbolForLabelAndString(ts,lbl,annotext,layerPtr->scalefactor,image->resolutionfactor, 1);

if(annotext && *annotext && lbl->autominfeaturesize && featuresize > 0) {
if(UNLIKELY(MS_FAILURE == msComputeTextPath(map,ts)))
if(UNLIKELY(MS_FAILURE == msComputeTextPath(map,ts))) {
freeTextSymbol(ts);
free(ts);
return MS_FAILURE;
}
if(featuresize < (ts->textpath->bounds.bbox.maxx - ts->textpath->bounds.bbox.minx)) {
/* feature is too big to be drawn, skip it */
freeTextSymbol(ts);
@@ -2106,7 +2106,7 @@ msINLINELayerInfo;

int msINLINELayerIsOpen(layerObj *layer)
{
if (layer->currentfeature)
if (layer->layerinfo)
return(MS_TRUE);
else
return(MS_FALSE);

Large diffs are not rendered by default.

@@ -61,8 +61,8 @@ static inline void IGUR_sizet(size_t ignored) { (void)ignored; } /* Ignore GCC
/* on the map. Layer name and Named Layer's name parameter are */
/* used to do the match. */
/************************************************************************/
int msSLDApplySLDURL(mapObj *map, char *szURL, int iLayer,
char *pszStyleLayerName, char **ppszLayerNames)
int msSLDApplySLDURL(mapObj *map, const char *szURL, int iLayer,
const char *pszStyleLayerName, char **ppszLayerNames)
{
#ifdef USE_OGR

@@ -116,6 +116,8 @@ int msSLDApplySLDURL(mapObj *map, char *szURL, int iLayer,
}
}

msFree(pszSLDbuf);

return nStatus;

#else
@@ -143,7 +145,7 @@ int msSLDApplySLDURL(mapObj *map, char *szURL, int iLayer,
/* they have the same name, copy the classes asscoaited with */
/* the SLD layers onto the map layers. */
/************************************************************************/
int msSLDApplySLD(mapObj *map, char *psSLDXML, int iLayer, char *pszStyleLayerName, char **ppszLayerNames)
int msSLDApplySLD(mapObj *map, const char *psSLDXML, int iLayer, const char *pszStyleLayerName, char **ppszLayerNames)
{
#if defined(USE_WMS_SVR) || defined (USE_WFS_SVR) || defined (USE_WCS_SVR) || defined(USE_SOS_SVR)

@@ -486,7 +488,7 @@ int msSLDApplySLD(mapObj *map, char *psSLDXML, int iLayer, char *pszStyleLayerNa
/* Returns an array of mapserver layers. The pnLayres if */
/* provided will indicate the size of the returned array. */
/************************************************************************/
layerObj *msSLDParseSLD(mapObj *map, char *psSLDXML, int *pnLayers)
layerObj *msSLDParseSLD(mapObj *map, const char *psSLDXML, int *pnLayers)
{
CPLXMLNode *psRoot = NULL;
CPLXMLNode *psSLD, *psNamedLayer, *psChild, *psName;
@@ -924,6 +926,7 @@ int msSLDParseNamedLayer(CPLXMLNode *psRoot, layerObj *psLayer)
char* pszExpression = msSLDGetCommonExpressionFromFilter(psFilter,
psLayer);
if (pszExpression) {
msFreeExpression(&psLayer->filter);
msInitExpression(&psLayer->filter);
psLayer->filter.string = pszExpression;
psLayer->filter.type = MS_EXPRESSION;
@@ -29,10 +29,10 @@
#include "mapserver.h"

MS_DLL_EXPORT char *msSLDGenerateSLD(mapObj *map, int iLayer, const char *pszVersion);
MS_DLL_EXPORT int msSLDApplySLDURL(mapObj *map, char *szURL, int iLayer,
char *pszStyleLayerName, char **ppszLayerNames);
MS_DLL_EXPORT int msSLDApplySLD(mapObj *map, char *psSLDXML, int iLayer,
char *pszStyleLayerName, char **ppszLayerNames);
MS_DLL_EXPORT int msSLDApplySLDURL(mapObj *map, const char *szURL, int iLayer,
const char *pszStyleLayerName, char **ppszLayerNames);
MS_DLL_EXPORT int msSLDApplySLD(mapObj *map, const char *psSLDXML, int iLayer,
const char *pszStyleLayerName, char **ppszLayerNames);

#ifdef USE_OGR

@@ -43,7 +43,7 @@ MS_DLL_EXPORT int msSLDApplySLD(mapObj *map, char *psSLDXML, int iLayer,
/* -------------------------------------------------------------------- */
/* prototypes. */
/* -------------------------------------------------------------------- */
layerObj *msSLDParseSLD(mapObj *map, char *psSLDXML, int *pnLayers);
layerObj *msSLDParseSLD(mapObj *map, const char *psSLDXML, int *pnLayers);
int msSLDParseNamedLayer(CPLXMLNode *psRoot, layerObj *layer);
int msSLDParseRule(CPLXMLNode *psRoot, layerObj *psLayer);
int msSLDParseStroke(CPLXMLNode *psStroke, styleObj *psStyle,
@@ -1713,10 +1713,8 @@ int msSOSGetObservation(mapObj *map, sosParamsObj *sosparams, cgiRequestObj *req
xmlNodePtr psObservationNode = NULL, psResultNode=NULL;
const char *pszProcedure = NULL;
const char *pszBlockSep=NULL;
char *pszResult=NULL;
int nDiffrentProc = 0;
SOSProcedureNode *paDiffrentProc = NULL;
char *pszProcedureValue = NULL;
int iItemPosition, status;
shapeObj sShape;
char* pszEscapedStr = NULL;
@@ -2303,6 +2301,7 @@ this request. Check sos/ows_enable_request settings.", "msSOSGetObservation()",
if (tokens==NULL || n != 4) {
msSetError(MS_SOSERR, "Wrong number of arguments for sos_offering_extent.",
"msSOSGetCapabilities()");
msFree(script_url);
return msSOSException(map, "sos_offering_extent", "InvalidParameterValue");
}

@@ -2314,6 +2313,7 @@ this request. Check sos/ows_enable_request settings.", "msSOSGetObservation()",
if (map && msProjectionsDiffer(&map->projection, &lp->projection) == MS_TRUE) {
if (msProjectRect(&lp->projection, &map->projection, &envelope) == MS_FAILURE) {
msSetError(MS_SOSERR, "Coordinates transformation failed. Raised in msProjectRect() of file %s line %d", "msSOSGetCapabilities()", __FILE__, __LINE__);
msFree(script_url);
return msSOSException(map, "sos_offering_extent", "InvalidParameterValue");
}
}
@@ -2352,6 +2352,14 @@ this request. Check sos/ows_enable_request settings.", "msSOSGetObservation()",
msSetError(MS_SOSERR, "resultModel should be om:Measurement or om:Observation", "msSOSGetObservation()");
free(xsi_schemaLocation);
free(schemalocation);
msFree(script_url);
xmlFreeNs(psNsSos);
xmlFreeNs(psNsGml);
xmlFreeNs(psNsOm);
xmlFreeNs(psNsSwe);
xmlFreeNs(psNsXLink);
xmlFreeNs(psNsMs);
xmlFreeDoc(psDoc);
return msSOSException(map, "resultModel", "InvalidParameterValue");
}

@@ -2391,10 +2399,12 @@ this request. Check sos/ows_enable_request settings.", "msSOSGetObservation()",
else
xmlNodeAddContent(psResultNode, BAD_CAST "\n");
}
pszResult = msSOSReturnMemberResult((GET_LAYER(map, i)), j, NULL);
if (pszResult) {
xmlNodeAddContent(psResultNode, BAD_CAST pszResult);
msFree(pszResult);
{
char* pszResult = msSOSReturnMemberResult((GET_LAYER(map, i)), j, NULL);
if (pszResult) {
xmlNodeAddContent(psResultNode, BAD_CAST pszResult);
msFree(pszResult);
}
}
}
}
@@ -2404,9 +2414,14 @@ this request. Check sos/ows_enable_request settings.", "msSOSGetObservation()",
else {

for(j=0; j<GET_LAYER(map, i)->resultcache->numresults; j++) {
pszResult = msSOSReturnMemberResult((GET_LAYER(map, i)), j, &pszProcedureValue);
char* pszProcedureValue = NULL;
char* pszResult = msSOSReturnMemberResult((GET_LAYER(map, i)), j, &pszProcedureValue);
if (!pszProcedureValue || !pszResult)
{
msFree(pszProcedureValue);
msFree(pszResult);
continue;
}
for (k=0; k<nDiffrentProc; k++) {
if (strcasecmp(paDiffrentProc[k].pszProcedure, pszProcedureValue) == 0) {
pszBlockSep = msOWSLookupMetadata(&(map->web.metadata), "S",
@@ -2432,14 +2447,14 @@ this request. Check sos/ows_enable_request settings.", "msSOSGetObservation()",
psObservationNode = msSOSAddMemberNodeObservation(psNsGml, psNsSos, psNsOm, psNsSwe, psNsXLink, psRootNode, map,
(GET_LAYER(map, i)),
pszProcedureValue);
msFree(pszProcedureValue);

paDiffrentProc[nDiffrentProc-1].psResultNode =
xmlNewChild(psObservationNode, NULL, BAD_CAST "result", NULL);

xmlNodeAddContent(paDiffrentProc[nDiffrentProc-1].psResultNode, BAD_CAST pszResult);
msFree(pszResult);
}
msFree(pszProcedureValue);
msFree(pszResult);
}
if (paDiffrentProc) {
for (k=0; k<nDiffrentProc; k++)
@@ -760,6 +760,8 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
"STORAGE=%s value not supported.",
"msOGRWriteFromQuery()",
storage );
CSLDestroy(layer_options);
CSLDestroy(ds_options);
return MS_FAILURE;
}

@@ -789,6 +791,9 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
"Attempt to create directory '%s' failed.",
"msOGRWriteFromQuery()",
dir_to_create );
msFree(request_dir);
CSLDestroy(layer_options);
CSLDestroy(ds_options);
return MS_FAILURE;
}
}
@@ -816,6 +821,9 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
"Invalid value for FILENAME option. "
"It must not contain any directory information.",
"msOGRWriteFromQuery()" );
msFree(request_dir);
CSLDestroy(layer_options);
CSLDestroy(ds_options);
return MS_FAILURE;
}

@@ -876,6 +884,7 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
"msOGRWriteFromQuery()",
datasource_name,
format->driver+4 );
CSLDestroy(layer_options);
return MS_FAILURE;
}

@@ -983,6 +992,7 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
"msOGRWriteFromQuery()",
layer->name,
format->driver+4 );
CSLDestroy(layer_options);
return MS_FAILURE;
}

@@ -1051,6 +1061,7 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
OGR_DS_Destroy( hDS );
msOGRCleanupDS( datasource_name );
msGMLFreeItems(item_list);
CSLDestroy(layer_options);
return MS_FAILURE;
}

@@ -1071,6 +1082,7 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
OGR_DS_Destroy( hDS );
msOGRCleanupDS( datasource_name );
msGMLFreeItems(item_list);
CSLDestroy(layer_options);
return status;
}
}
@@ -1101,6 +1113,7 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
msOGRCleanupDS( datasource_name );
msGMLFreeItems(item_list);
msFreeShape(&resultshape);
CSLDestroy(layer_options);
return status;
}
}
@@ -1152,6 +1165,7 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
msOGRCleanupDS( datasource_name );
msGMLFreeItems(item_list);
msFreeShape(&resultshape);
CSLDestroy(layer_options);
return status;
}
}
@@ -1165,6 +1179,8 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
/* -------------------------------------------------------------------- */
OGR_DS_Destroy( hDS );

CSLDestroy( layer_options );

/* -------------------------------------------------------------------- */
/* Get list of resulting files. */
/* -------------------------------------------------------------------- */
@@ -1366,7 +1382,6 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )

msOGRCleanupDS( datasource_name );

CSLDestroy( layer_options );
CSLDestroy( file_list );

return MS_SUCCESS;
@@ -2002,13 +2002,16 @@ int msOWSPrintEncodeMetadataList(FILE *stream, hashTableObj *metadata,
{
const char *value;
char *encoded;
size_t default_value_len = 0;

value = msOWSLookupMetadata(metadata, namespaces, name);

if(value == NULL) {
value = default_value;
default_value = NULL;
}
if( default_value )
default_value_len = strlen(default_value);

if(value != NULL) {
char **keywords;
@@ -2020,8 +2023,9 @@ int msOWSPrintEncodeMetadataList(FILE *stream, hashTableObj *metadata,
if(startTag) msIO_fprintf(stream, "%s", startTag);
for(kw=0; kw<numkeywords; kw++) {
if (default_value != NULL
&& default_value_len > 8
&& strncasecmp(keywords[kw],default_value,strlen(keywords[kw])) == 0
&& strncasecmp("_exclude",default_value+strlen(default_value)-8,8) == 0)
&& strncasecmp("_exclude",default_value+default_value_len-8,8) == 0)
continue;

encoded = msEncodeHTMLEntities(keywords[kw]);
@@ -819,6 +819,7 @@ int msQueryByFilter(mapObj *map)
*/
lp->filteritem = map->query.filteritem; /* re-point lp->filteritem */
if(old_filter.string != NULL) { /* need to merge filters to create one logical expression */
msFreeExpression(&lp->filter);
lp->filter = mergeFilters(&map->query.filter, map->query.filteritem, &old_filter, old_filteritem);
if(!lp->filter.string) {
msSetError(MS_MISCERR, "Filter merge failed, able to process query.", "msQueryByFilter()");

0 comments on commit d7b11f3

Please sign in to comment.
You can’t perform that action at this time.