Index: mapraster.c =================================================================== RCS file: /data2/cvsroot/mapserver/mapraster.c,v retrieving revision 1.117 diff -u -r1.117 mapraster.c --- mapraster.c 1 Jun 2004 14:33:43 -0000 1.117 +++ mapraster.c 2 Jun 2004 16:05:19 -0000 @@ -1201,6 +1201,7 @@ char *filename=NULL, tilename[MS_MAXPATHLEN]; layerObj *tlp=NULL; // pointer to the tile layer either real or temporary + int tlptemp = 0; int tileitemindex=-1, tilelayerindex=-1; shapeObj tshp; @@ -1283,6 +1284,7 @@ msSetError(MS_MEMERR, "Error allocating temporary layerObj.", "msDrawRasterLayerLow()"); return(MS_FAILURE); } + tlptemp = 1; initLayer(tlp, map); // set a few parameters for a very basic shapefile-based layer @@ -1293,12 +1295,12 @@ tlp = &(layer->map->layers[tilelayerindex]); status = msLayerOpen(tlp); - if(status != MS_SUCCESS) return(MS_FAILURE); + if(status != MS_SUCCESS) goto cleanup; // build item list (no annotation) since we may have to classify the shape, plus we want the tileitem status = msLayerWhichItems(tlp, MS_TRUE, MS_FALSE, layer->tileitem); - if(status != MS_SUCCESS) return(MS_FAILURE); - + if(status != MS_SUCCESS) goto cleanup; + // get the tileitem index for(i=0; inumitems; i++) { if(strcasecmp(tlp->items[i], layer->tileitem) == 0) { @@ -1308,7 +1310,7 @@ } if(i == tlp->numitems) { // didn't find it msSetError(MS_MEMERR, "Could not find attribute %s in tileindex.", "msDrawRasterLayerLow()", layer->tileitem); - return(MS_FAILURE); + if(status != MS_SUCCESS) goto cleanup; } searchrect = map->extent; @@ -1317,14 +1319,14 @@ if((map->projection.numargs > 0) && (layer->projection.numargs > 0)) msProjectRect(&map->projection, &layer->projection, &searchrect); #endif status = msLayerWhichShapes(tlp, searchrect); - if(status != MS_SUCCESS) return(MS_FAILURE); // TODO: probably need more clean up here + if(status != MS_SUCCESS) goto cleanup; } done = MS_FALSE; while(done != MS_TRUE) { if(layer->tileindex) { status = msLayerNextShape(tlp, &tshp); - if(status == MS_FAILURE) return(MS_FAILURE); + if(status != MS_SUCCESS) goto cleanup; if(status == MS_DONE) break; // no more tiles/images if(layer->data == NULL) // assume whole filename is in attribute field @@ -1355,7 +1357,7 @@ if((memcmp(dd,"II*\0",4)==0 || memcmp(dd,"MM\0*",4)==0) && !force_gdal) { status = drawTIFF(map, layer, img, filename); if(status == -1) { - return(MS_FAILURE); + goto cleanup; } continue; } @@ -1363,7 +1365,7 @@ if(memcmp(dd,"GIF8",4)==0 && !force_gdal ) { status = drawGIF(map, layer, img, filename); if(status == -1) { - return(MS_FAILURE); + goto cleanup; } continue; } @@ -1371,7 +1373,7 @@ if(memcmp(dd,PNGsig,8)==0 && !force_gdal) { status = drawPNG(map, layer, img, filename); if(status == -1) { - return(MS_FAILURE); + goto cleanup; } continue; } @@ -1379,7 +1381,7 @@ if(memcmp(dd,JPEGsig,3)==0 && !force_gdal) { status = drawJPEG(map, layer, img, filename); if(status == -1) { - return(MS_FAILURE); + goto cleanup; } continue; } @@ -1422,7 +1424,8 @@ szLongMsg); msReleaseLock( TLOCK_GDAL ); - return(MS_FAILURE); + status = MS_FAILURE; + goto cleanup; } } } @@ -1461,7 +1464,8 @@ { GDALClose( hDS ); msReleaseLock( TLOCK_GDAL ); - return MS_FAILURE; + status = MS_FAILURE; + goto cleanup; } GDALClose( hDS ); @@ -1485,7 +1489,8 @@ if( layer->debug || map->debug ) msDebug( "Unable to open file %s for layer %s ... fatal error.\n", filename, layer->name ); - return(MS_FAILURE); + status = MS_FAILURE; + goto cleanup; #else if( layer->debug || map->debug ) msDebug( "Unable to open file %s for layer %s ... ignoring this missing data.\n", filename, layer->name ); @@ -1501,20 +1506,21 @@ if(status != 0) { if (status == -2) msSetError(MS_IMGERR, "Error reading EPPL file; probably corrupt.", "msDrawEPP()"); if (status == -1) msSetError(MS_IMGERR, "Unrecognized or unsupported image format", "msDrawRaster()"); - return(MS_FAILURE); + goto cleanup; } continue; } // next tile +cleanup: if(layer->tileindex) { // tiling clean-up msLayerClose(tlp); - if(tileitemindex == -1) { + if(tlptemp) { freeLayer(tlp); free(tlp); } } - - return 0; + + return status; } /************************************************************************/