Skip to content

Commit

Permalink
more valgrind leaks (wcs,sos)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbonfort committed Sep 17, 2012
1 parent dadbfad commit 243a2ea
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 12 deletions.
7 changes: 5 additions & 2 deletions mapogcsos.c
Expand Up @@ -102,7 +102,7 @@ static int msSOSException(mapObj *map, char *locator, char *exceptionCode)

xmlDocSetRootElement(psDoc, psRootNode);

psNsOws = xmlNewNs(psRootNode, BAD_CAST "http://www.opengis.net/ows/1.1", BAD_CAST "ows");
xmlNewNs(psRootNode, BAD_CAST "http://www.opengis.net/ows/1.1", BAD_CAST "ows");

if (encoding)
msIO_setHeader("Content-type","text/xml; charset=%s", encoding);
Expand All @@ -120,6 +120,7 @@ static int msSOSException(mapObj *map, char *locator, char *exceptionCode)
free(schemasLocation);
xmlFree(buffer);
xmlFreeDoc(psDoc);
xmlFreeNs(psNsOws);

/*
** The typical pattern is to call msSOSException() right after
Expand Down Expand Up @@ -932,6 +933,7 @@ char* msSOSReturnMemberResult(layerObj *lp, int iFeatureId, char **ppszProcedure
}
}
}
msFreeShape(&sShape);
return pszFinalValue;
}

Expand Down Expand Up @@ -2538,11 +2540,12 @@ int msSOSDescribeSensor(mapObj *map, sosParamsObj *sosparams, owsRequestObj *ows
bFound = 1;
pszProcedureId = msStrdup(tokens[k]);
msFree(pszProcedureURI);
msFreeCharArray(tokens, n);
break;
}
msFree(pszProcedureURI);
}
}
msFreeCharArray(tokens, n);
if (bFound) {
pszUrl = msOWSLookupMetadata(&(lp->metadata), "S", "describesensor_url");
if (pszUrl) {
Expand Down
18 changes: 14 additions & 4 deletions mapwcs.c
Expand Up @@ -962,7 +962,7 @@ static int msWCSGetCapabilities(mapObj *map, wcsParamsObj *params, cgiRequestObj

else { /* set default updatesequence */
if(!updatesequence)
updatesequence = msStrdup("0");
updatesequence = "0";
params->updatesequence = msStrdup(updatesequence);
}

Expand Down Expand Up @@ -995,7 +995,7 @@ static int msWCSGetCapabilities(mapObj *map, wcsParamsObj *params, cgiRequestObj
/* TODO: DocType? */

if (!updatesequence)
updatesequence = msStrdup("0");
updatesequence = "0";

msOWSPrintEncodeMetadata(stdout, &(map->web.metadata), NULL, "wcs_encoding", OWS_NOERR, "<?xml version='1.0' encoding=\"%s\" standalone=\"no\" ?>\n", "ISO-8859-1");

Expand Down Expand Up @@ -1280,6 +1280,7 @@ static int msWCSDescribeCoverage_CoverageOffering(layerObj *layer, wcsParamsObj
if( (value = msOWSGetEncodeMetadata( &(layer->metadata), "CO", "formats",
"GTiff" )) != NULL ) {
tokens = msStringSplit(value, ' ', &numtokens);
msFree((char*)value);
if(tokens && numtokens > 0) {
for(i=0; i<numtokens; i++)
msIO_printf(" <formats>%s</formats>\n", tokens[i]);
Expand Down Expand Up @@ -1335,8 +1336,11 @@ static int msWCSDescribeCoverage(mapObj *map, wcsParamsObj *params, owsRequestOb
for(i=0; i<map->numlayers; i++) {
coverageName = msOWSGetEncodeMetadata(&(GET_LAYER(map, i)->metadata), "CO", "name", GET_LAYER(map, i)->name);
if( EQUAL(coverageName, coverages[k]) &&
(msIntegerInArray(GET_LAYER(map, i)->index, ows_request->enabled_layers, ows_request->numlayers)) )
(msIntegerInArray(GET_LAYER(map, i)->index, ows_request->enabled_layers, ows_request->numlayers)) ) {
msFree(coverageName);
break;
}
msFree(coverageName);
}

/* i = msGetLayerIndex(map, coverages[k]); */
Expand All @@ -1346,6 +1350,7 @@ this request. Check wcs/ows_enable_request settings.", "msWCSDescribeCoverage()"
return msWCSException(map, "CoverageNotDefined", "coverage", params->version );
}
} /* next coverage */
msFreeCharArray(coverages,numcoverages);
}
}

Expand Down Expand Up @@ -1378,10 +1383,15 @@ this request. Check wcs/ows_enable_request settings.", "msWCSDescribeCoverage()"
for(k=0; k<numcoverages; k++) {
for(i=0; i<map->numlayers; i++) {
coverageName = msOWSGetEncodeMetadata(&(GET_LAYER(map, i)->metadata), "CO", "name", GET_LAYER(map, i)->name);
if( EQUAL(coverageName, coverages[k]) ) break;
if( EQUAL(coverageName, coverages[k]) ) {
msFree(coverageName);
break;
}
msFree(coverageName);
}
msWCSDescribeCoverage_CoverageOffering((GET_LAYER(map, i)), params);
}
msFreeCharArray(coverages,numcoverages);
}
} else { /* return all layers */
for(i=0; i<map->numlayers; i++) {
Expand Down
20 changes: 15 additions & 5 deletions mapwcs11.c
Expand Up @@ -72,7 +72,6 @@ int msWCSException11(mapObj *map, const char *locator,
xmlChar *buffer = NULL;

psNsOws = xmlNewNs(NULL, BAD_CAST "http://www.opengis.net/ows/1.1", BAD_CAST "ows");
//TODO leak?

encoding = msOWSLookupMetadata(&(map->web.metadata), "CO", "encoding");
errorString = msGetErrorString("\n");
Expand All @@ -85,8 +84,7 @@ int msWCSException11(mapObj *map, const char *locator,

xmlDocSetRootElement(psDoc, psRootNode);

psNsOws = xmlNewNs(psRootNode, BAD_CAST "http://www.opengis.net/ows/1.1", BAD_CAST "ows");
//TODO leak?
xmlNewNs(psRootNode, BAD_CAST "http://www.opengis.net/ows/1.1", BAD_CAST "ows");

if (encoding)
msIO_setHeader("Content-type","text/xml; charset=%s", encoding);
Expand All @@ -104,6 +102,7 @@ int msWCSException11(mapObj *map, const char *locator,
free(schemasLocation);
xmlFree(buffer);
xmlFreeDoc(psDoc);
xmlFreeNs(psNsOws);

/* clear error since we have already reported it */
msResetErrorList();
Expand All @@ -125,7 +124,7 @@ static char *msWCSGetFormatsList11( mapObj *map, layerObj *layer )
char *format_list = msStrdup("");
char **tokens = NULL, **formats = NULL;
int i, numtokens = 0, numformats;
const char *value;
char *value;

msApplyDefaultOutputFormats(map);

Expand All @@ -136,6 +135,7 @@ static char *msWCSGetFormatsList11( mapObj *map, layerObj *layer )
&& (value = msOWSGetEncodeMetadata( &(layer->metadata),"CO","formats",
"GTiff" )) != NULL ) {
tokens = msStringSplit(value, ' ', &numtokens);
msFree(value);
}

/* -------------------------------------------------------------------- */
Expand All @@ -144,6 +144,7 @@ static char *msWCSGetFormatsList11( mapObj *map, layerObj *layer )
else if((value = msOWSGetEncodeMetadata( &(map->web.metadata), "CO", "formats",
NULL)) != NULL ) {
tokens = msStringSplit(value, ' ', &numtokens);
msFree(value);
}

/* -------------------------------------------------------------------- */
Expand Down Expand Up @@ -461,6 +462,8 @@ int msWCSGetCapabilities11(mapObj *map, wcsParamsObj *params,
xsi_schemaLocation = msStringConcatenate(xsi_schemaLocation, schemaLocation);
xsi_schemaLocation = msStringConcatenate(xsi_schemaLocation, "/ows/1.1.0/owsAll.xsd");
xmlNewNsProp(psRootNode, NULL, BAD_CAST "xsi:schemaLocation", BAD_CAST xsi_schemaLocation);
msFree(schemaLocation);
msFree(xsi_schemaLocation);

/* -------------------------------------------------------------------- */
/* Service metadata. */
Expand Down Expand Up @@ -775,7 +778,7 @@ msWCSDescribeCoverage_CoverageDescription11(
/* -------------------------------------------------------------------- */
{
xmlNodePtr psField, psInterpMethods, psAxis;
const char *value;
char *value;

psField =
xmlNewChild(
Expand All @@ -786,12 +789,15 @@ msWCSDescribeCoverage_CoverageDescription11(
"rangeset_label", NULL );
if( value )
xmlNewChild( psField, psOwsNs, BAD_CAST "Title", BAD_CAST value );
msFree(value);


/* ows:Abstract? TODO */

value = msOWSGetEncodeMetadata( &(layer->metadata), "CO",
"rangeset_name", "raster" );
xmlNewChild( psField, NULL, BAD_CAST "Identifier", BAD_CAST value );
msFree(value);

xmlNewChild(
xmlNewChild( psField, NULL, BAD_CAST "Definition", NULL ),
Expand All @@ -803,6 +809,7 @@ msWCSDescribeCoverage_CoverageDescription11(
if( value )
xmlNewChild( psField, NULL, BAD_CAST "NullValue",
BAD_CAST value );
msFree(value);

/* InterpolationMethods */
psInterpMethods =
Expand All @@ -823,6 +830,7 @@ msWCSDescribeCoverage_CoverageDescription11(
"bands_name", "bands" );
psAxis = xmlNewChild( psField, NULL, BAD_CAST "Axis", NULL );
xmlNewProp( psAxis, BAD_CAST "identifier", BAD_CAST value );
msFree(value);

psKeys = xmlNewChild( psAxis, NULL, BAD_CAST
"AvailableKeys", NULL );
Expand Down Expand Up @@ -954,6 +962,8 @@ int msWCSDescribeCoverage11(mapObj *map, wcsParamsObj *params, owsRequestObj *ow
xsi_schemaLocation = msStringConcatenate(xsi_schemaLocation, schemaLocation);
xsi_schemaLocation = msStringConcatenate(xsi_schemaLocation, "/ows/1.1.0/owsAll.xsd");
xmlNewNsProp(psRootNode, NULL, BAD_CAST "xsi:schemaLocation", BAD_CAST xsi_schemaLocation);
msFree(schemaLocation);
msFree(xsi_schemaLocation);

/* -------------------------------------------------------------------- */
/* Generate a CoverageDescription for each requested coverage. */
Expand Down
22 changes: 21 additions & 1 deletion mapwcs20.c
Expand Up @@ -1556,6 +1556,7 @@ static void msWCSCommon20_CreateRangeType(layerObj* layer, wcs20coverageMetadata
xmlNewChild(psAllowedValues, psSweNs, BAD_CAST "significantFigures", BAD_CAST significant_figures);
}
}
msFreeCharArray(arr,num);
}

/************************************************************************/
Expand Down Expand Up @@ -3165,7 +3166,10 @@ this request. Check wcs/ows_enable_request settings.", "msWCSGetCoverage20()", p
}
/* retrieve coverage metadata */
status = msWCSGetCoverageMetadata20(layer, &cm);
if (status != MS_SUCCESS) return MS_FAILURE;
if (status != MS_SUCCESS) {
msWCSClearCoverageMetadata20(&cm);
return MS_FAILURE;
}

/* fill in bands rangeset info, if required. */
/* msWCSSetDefaultBandsRangeSetInfo(NULL, &cm, layer ); */
Expand All @@ -3186,11 +3190,13 @@ this request. Check wcs/ows_enable_request settings.", "msWCSGetCoverage20()", p
msSetError(MS_WCSERR,
"Error loading CRS %s.",
"msWCSGetCoverage20()", params->subsetcrs);
msWCSClearCoverageMetadata20(&cm);
return msWCSException(map, "InvalidParameterValue",
"projection", params->version);
}

if(msWCSGetCoverage20_FinalizeParamsObj(params) == MS_FAILURE) {
msWCSClearCoverageMetadata20(&cm);
return msWCSException(map, "InvalidParameterValue", "extent", params->version);
}

Expand Down Expand Up @@ -3235,6 +3241,7 @@ this request. Check wcs/ows_enable_request settings.", "msWCSGetCoverage20()", p
msSetError(MS_WCSERR,
"Error loading CRS %s.",
"msWCSGetCoverage20()", params->subsetcrs);
msWCSClearCoverageMetadata20(&cm);
return msWCSException(map, "InvalidParameterValue",
"projection", params->version);
}
Expand All @@ -3257,6 +3264,7 @@ this request. Check wcs/ows_enable_request settings.", "msWCSGetCoverage20()", p
/* extent and bbox do not overlap -> exit */
msSetError(MS_WCSERR, "Image extent does not intersect with desired region.",
"msWCSGetCoverage20()");
msWCSClearCoverageMetadata20(&cm);
return msWCSException(map, "ExtentError", "extent", params->version);
}

Expand All @@ -3271,6 +3279,7 @@ this request. Check wcs/ows_enable_request settings.", "msWCSGetCoverage20()", p
|| (params->height != 0 && params->resolutionY != MS_WCS20_UNBOUNDED)) {
msSetError(MS_WCSERR, "GetCoverage operation supports only one of SIZE or RESOLUTION per axis.",
"msWCSGetCoverage20()");
msWCSClearCoverageMetadata20(&cm);
return msWCSException(map, "TooManyParameterValues", "coverage",
params->version);
}
Expand Down Expand Up @@ -3329,6 +3338,7 @@ this request. Check wcs/ows_enable_request settings.", "msWCSGetCoverage20()", p
msInitProjection(&outputProj);
if(msLoadProjectionString(&outputProj, params->outputcrs) == -1) {
msFreeProjection(&outputProj);
msWCSClearCoverageMetadata20(&cm);
return msWCSException(map, "InvalidParameterValue", "coverage",
params->version);
}
Expand Down Expand Up @@ -3357,6 +3367,7 @@ this request. Check wcs/ows_enable_request settings.", "msWCSGetCoverage20()", p
"resulting coverage must be no more than MAXSIZE=%d.",
"msWCSGetCoverage20()", map->maxsize);

msWCSClearCoverageMetadata20(&cm);
return msWCSException(map, "InvalidParameterValue",
"size", params->version);
}
Expand Down Expand Up @@ -3390,6 +3401,7 @@ this request. Check wcs/ows_enable_request settings.", "msWCSGetCoverage20()", p
msSetError(MS_WCSERR, "Output format could not be automatically determined. "
"Use the FORMAT parameter to specify a format.",
"msWCSGetCoverage20()");
msWCSClearCoverageMetadata20(&cm);
return msWCSException(map, "MissingParameterValue", "format",
params->version);
}
Expand All @@ -3408,6 +3420,7 @@ this request. Check wcs/ows_enable_request settings.", "msWCSGetCoverage20()", p
if (msGetOutputFormatIndex(map, params->format) == -1) {
msSetError(MS_WCSERR, "Unrecognized value '%s' for the FORMAT parameter.",
"msWCSGetCoverage20()", params->format);
msWCSClearCoverageMetadata20(&cm);
return msWCSException(map, "InvalidParameterValue", "format",
params->version);
}
Expand All @@ -3418,6 +3431,7 @@ this request. Check wcs/ows_enable_request settings.", "msWCSGetCoverage20()", p
MS_NOOVERRIDE, MS_NOOVERRIDE);

if(msWCSGetCoverage20_GetBands(map, layer, params, &cm, &bandlist) != MS_SUCCESS) {
msWCSClearCoverageMetadata20(&cm);
return msWCSException(map, "InvalidParameterValue", "rangesubset",
params->version);
}
Expand All @@ -3437,6 +3451,7 @@ this request. Check wcs/ows_enable_request settings.", "msWCSGetCoverage20()", p
} else {
msSetError( MS_WCSERR, "'%s' specifies an unsupported interpolation method.",
"msWCSGetCoverage20()", params->interpolation );
msWCSClearCoverageMetadata20(&cm);
return msWCSException(map, "InvalidParameterValue", "interpolation", params->version);
}
} else {
Expand All @@ -3455,6 +3470,7 @@ this request. Check wcs/ows_enable_request settings.", "msWCSGetCoverage20()", p
if (!map->outputformat) {
msSetError(MS_WCSERR, "The map outputformat is missing!",
"msWCSGetCoverage20()");
msWCSClearCoverageMetadata20(&cm);
return msWCSException(map, NULL, NULL, params->version);
} else if (MS_RENDERER_PLUGIN(map->outputformat)) {
image = msImageCreate(map->width, map->height, map->outputformat,
Expand All @@ -3466,13 +3482,15 @@ this request. Check wcs/ows_enable_request settings.", "msWCSGetCoverage20()", p
map->defresolution, &map->imagecolor);
} else {
msFree(bandlist);
msWCSClearCoverageMetadata20(&cm);
msSetError(MS_WCSERR, "Map outputformat not supported for WCS!",
"msWCSGetCoverage20()");
return msWCSException(map, NULL, NULL, params->version);
}

if (image == NULL) {
msFree(bandlist);
msWCSClearCoverageMetadata20(&cm);
return msWCSException(map, NULL, NULL, params->version);
}

Expand All @@ -3488,6 +3506,7 @@ this request. Check wcs/ows_enable_request settings.", "msWCSGetCoverage20()", p
if( status != MS_SUCCESS ) {
msFree(bandlist);
msFreeImage(image);
msWCSClearCoverageMetadata20(&cm);
return msWCSException(map, NULL, NULL, params->version );
}

Expand Down Expand Up @@ -3560,6 +3579,7 @@ this request. Check wcs/ows_enable_request settings.", "msWCSGetCoverage20()", p
file_ref = msSmallMalloc(length);
strlcpy(file_ref, "cid:coverage/", length);
strlcat(file_ref, filename, length);
msFree(default_filename);

if(EQUAL(MS_IMAGE_MIME_TYPE(map->outputformat), "image/tiff")) {
length = strlen(MS_WCS_20_PROFILE_GML_GEOTIFF) + 1;
Expand Down
1 change: 1 addition & 0 deletions mapwms.c
Expand Up @@ -3303,6 +3303,7 @@ int msWMSGetCapabilities(mapObj *map, int nVersion, cgiRequestObj *req, owsReque
msFree(pszLegendURL);
msFree(pszMimetype);
}
msFree(group_layers);
}
msIO_fprintf(stdout, " </Style>\n");
msFree(pszEncodedName);
Expand Down

0 comments on commit 243a2ea

Please sign in to comment.