Skip to content

Commit

Permalink
fix various leaks found by valgrind
Browse files Browse the repository at this point in the history
  • Loading branch information
tbonfort committed Sep 17, 2012
1 parent e65d834 commit a38a32e
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 7 deletions.
4 changes: 4 additions & 0 deletions mapcairo.c
Expand Up @@ -1191,6 +1191,10 @@ int msRenderRasterizedSVGSymbol(imageObj *img, double x, double y, symbolObj *sy
#endif
}

void msCairoCleanup() {
cairo_debug_reset_static_data();
}

#endif /*USE_CAIRO*/


Expand Down
1 change: 1 addition & 0 deletions mapdrawgdal.c
Expand Up @@ -2042,6 +2042,7 @@ msDrawRasterLayerGDAL_RawMode(
}

free( pBuffer );
free( f_nodatas );

return 0;
}
Expand Down
1 change: 1 addition & 0 deletions mapgeomtransform.c
Expand Up @@ -190,6 +190,7 @@ int msDrawTransformedShape(mapObj *map, symbolSetObj *symbolset, imageObj *image
msDrawShadeSymbol(symbolset, image, tmpshp, style, scalefactor);

msFreeShape(tmpshp);
msFree(tmpshp);
}
break;
case MS_GEOMTRANSFORM_LABELPOINT:
Expand Down
1 change: 1 addition & 0 deletions mapgeos.c
Expand Up @@ -205,6 +205,7 @@ static GEOSGeom msGEOSShape2Geometry_simplepolygon(shapeObj *shape, int r, int *
g = GEOSGeom_createPolygon(outerRing, innerRings, numInnerRings);

free(innerList); /* clean up */
free(innerRings); /* clean up */

return g;
}
Expand Down
3 changes: 3 additions & 0 deletions mapgraticule.c
Expand Up @@ -91,14 +91,17 @@ int msGraticuleLayerOpen(layerObj *layer)
pInfo->ilabeltype = (int) lpDefault;
strcpy( pInfo->labelformat, MAPGRATICULE_FORMAT_STRING_DEFAULT );
} else if( strcmp( pInfo->labelformat, "DDMMSS" ) == 0 ) {
msFree(pInfo->labelformat);
pInfo->labelformat = (char *) msSmallMalloc( strlen( MAPGRATICULE_FORMAT_STRING_DDMMSS ) + 1 );
pInfo->ilabeltype = (int) lpDDMMSS;
strcpy( pInfo->labelformat, MAPGRATICULE_FORMAT_STRING_DDMMSS );
} else if( strcmp( pInfo->labelformat, "DDMM" ) == 0 ) {
msFree(pInfo->labelformat);
pInfo->labelformat = (char *) msSmallMalloc( strlen( MAPGRATICULE_FORMAT_STRING_DDMM ) + 1 );
pInfo->ilabeltype = (int) lpDDMM;
strcpy( pInfo->labelformat, MAPGRATICULE_FORMAT_STRING_DDMM );
} else if( strcmp( pInfo->labelformat, "DD" ) == 0 ) {
msFree(pInfo->labelformat);
pInfo->labelformat = (char *) msSmallMalloc( strlen( MAPGRATICULE_FORMAT_STRING_DD ) + 1 );
pInfo->ilabeltype = (int) lpDD;
strcpy( pInfo->labelformat, MAPGRATICULE_FORMAT_STRING_DD );
Expand Down
3 changes: 3 additions & 0 deletions mapproject.h
Expand Up @@ -39,6 +39,9 @@ extern "C" {

#ifdef USE_PROJ
# include <proj_api.h>
#if PJ_VERSION >= 470 && PJ_VERSION < 480
void pj_clear_initcache();
#endif
#endif

#define wkp_none 0
Expand Down
3 changes: 3 additions & 0 deletions mapserver.h
Expand Up @@ -2729,6 +2729,9 @@ extern "C" {
MS_DLL_EXPORT int msPopulateRendererVTableGD( rendererVTableObj *renderer );
MS_DLL_EXPORT int msPopulateRendererVTableKML( rendererVTableObj *renderer );
MS_DLL_EXPORT int msPopulateRendererVTableOGR( rendererVTableObj *renderer );
#ifdef CAIRO
MS_DLL_EXPORT void msCairoCleanup();
#endif

/* allocate 50k for starters */
#define MS_DEFAULT_BUFFER_ALLOC 50000
Expand Down
26 changes: 20 additions & 6 deletions maptemplate.c
Expand Up @@ -872,16 +872,17 @@ static int processFeatureTag(mapservObj *mapserv, char **line, layerObj *layer)

argValue = msLookupHashTable(tagArgs, "trimlast");
if(argValue) trimLast = argValue;
msFreeHashTable(tagArgs);
}

if(strstr(*line, "[/feature]") == NULL) { /* we know the closing tag must be here, if not throw an error */
msSetError(MS_WEBERR, "[feature] tag found without closing [/feature].", "processFeatureTag()");
msFreeHashTable(tagArgs);
return(MS_FAILURE);
}

if(getInlineTag("feature", *line, &tag) != MS_SUCCESS) {
msSetError(MS_WEBERR, "Malformed feature tag.", "processFeatureTag()");
msFreeHashTable(tagArgs);
return MS_FAILURE;
}

Expand All @@ -904,7 +905,10 @@ static int processFeatureTag(mapservObj *mapserv, char **line, layerObj *layer)
if(layer->numjoins > 0) { /* initialize necessary JOINs here */
for(j=0; j<layer->numjoins; j++) {
status = msJoinConnect(layer, &(layer->joins[j]));
if(status != MS_SUCCESS) return status;
if(status != MS_SUCCESS) {
msFreeHashTable(tagArgs);
return status;
}
}
}

Expand All @@ -919,7 +923,10 @@ static int processFeatureTag(mapservObj *mapserv, char **line, layerObj *layer)

for(i=0; i<limit; i++) {
status = msLayerGetShape(layer, &(mapserv->resultshape), &(layer->resultcache->results[i]));
if(status != MS_SUCCESS) return status;
if(status != MS_SUCCESS) {
msFreeHashTable(tagArgs);
return status;
}

mapserv->resultshape.classindex = msShapeGetClass(layer, layer->map, &mapserv->resultshape, NULL, -1);

Expand Down Expand Up @@ -967,6 +974,7 @@ static int processFeatureTag(mapservObj *mapserv, char **line, layerObj *layer)
*/
free(postTag);
free(tag);
msFreeHashTable(tagArgs);

return(MS_SUCCESS);
}
Expand Down Expand Up @@ -1008,25 +1016,26 @@ static int processResultSetTag(mapservObj *mapserv, char **line, FILE *stream)
if(tagArgs) {
layerName = msLookupHashTable(tagArgs, "layer");
nodata = msLookupHashTable(tagArgs, "nodata");
msFreeHashTable(tagArgs);
tagArgs=NULL;
}

if(!layerName) {
msSetError(MS_WEBERR, "[resultset] tag missing required 'layer' argument.", "processResultSetTag()");
msFreeHashTable(tagArgs);
return(MS_FAILURE);
}

layerIndex = msGetLayerIndex(mapserv->map, layerName);
if(layerIndex>=mapserv->map->numlayers || layerIndex<0) {
msSetError(MS_MISCERR, "Layer named '%s' does not exist.", "processResultSetTag()", layerName);
msFreeHashTable(tagArgs);
return MS_FAILURE;
}
lp = GET_LAYER(mapserv->map, layerIndex);

if(strstr(*line, "[/resultset]") == NULL) { /* read ahead */
if(!stream) {
msSetError(MS_WEBERR, "Invalid file pointer.", "processResultSetTag()");
msFreeHashTable(tagArgs);
return(MS_FAILURE);
}

Expand All @@ -1041,12 +1050,14 @@ static int processResultSetTag(mapservObj *mapserv, char **line, FILE *stream)
}
if(foundTagEnd == MS_FALSE) {
msSetError(MS_WEBERR, "[resultset] tag found without closing [/resultset].", "processResultSetTag()");
msFreeHashTable(tagArgs);
return(MS_FAILURE);
}
}

if(getInlineTag("resultset", *line, &tag) != MS_SUCCESS) {
msSetError(MS_WEBERR, "Malformed resultset tag.", "processResultSetTag()");
msFreeHashTable(tagArgs);
return MS_FAILURE;
}

Expand All @@ -1059,8 +1070,10 @@ static int processResultSetTag(mapservObj *mapserv, char **line, FILE *stream)

if(lp->resultcache && lp->resultcache->numresults > 0) {
/* probably will need a while-loop here to handle multiple instances of [feature ...] tags */
if(processFeatureTag(mapserv, &tag, lp) != MS_SUCCESS)
if(processFeatureTag(mapserv, &tag, lp) != MS_SUCCESS) {
msFreeHashTable(tagArgs);
return(MS_FAILURE); /* TODO: how to handle */
}
*line = msStringConcatenate(*line, tag);
} else if(nodata) {
*line = msStringConcatenate(*line, nodata);
Expand All @@ -1074,6 +1087,7 @@ static int processResultSetTag(mapservObj *mapserv, char **line, FILE *stream)

tagStart = findTag(*line, "resultset");
}
msFreeHashTable(tagArgs);

return(MS_SUCCESS);
}
Expand Down
6 changes: 5 additions & 1 deletion maputil.c
Expand Up @@ -1865,7 +1865,7 @@ void msCleanup(int signal)
msGDALCleanup();
#endif
#ifdef USE_PROJ
# if PJ_VERSION >= 480
# if PJ_VERSION >= 470
pj_clear_initcache();
# endif
pj_deallocate_grids();
Expand All @@ -1883,6 +1883,10 @@ void msCleanup(int signal)
msGEOSCleanup();
#endif

#ifdef USE_CAIRO
msCairoCleanup();
#endif

msIO_Cleanup();

msResetErrorList();
Expand Down

0 comments on commit a38a32e

Please sign in to comment.