Changeset 102 for trunk


Ignore:
Timestamp:
Feb 1, 2011, 2:50:33 PM (14 years ago)
Author:
djay
Message:

Update the Profile service to release memory after using it. Special thanks to Luiz Mota for pointing out those not-freed blocks.

Location:
trunk/zoo-services/gdal/profile
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-services/gdal/profile/cgi-env/GdalExtractProfile.zcfg

    r80 r102  
    77 serviceType = C
    88 serviceProvider = gdal_profile_service.zo
    9  <MetaData>
     9 <MetaData lang="en">
    1010   title = My Demo
    1111 </MetaData>
     
    2121     value = topofr.tif
    2222    </Default>
    23     <Supported>
    24     </Supported>
    2523   </LiteralData>
    2624  [Geometry]
  • trunk/zoo-services/gdal/profile/service.c

    r50 r102  
    77 *
    88 * ****************************************************************************
    9  * Copyright (c) 2010, GeoLabs SARL
     9 * Copyright (c) 2010-2011, GeoLabs SARL
    1010 *
    1111 * Permission is hereby granted, free of charge, to any person obtaining a
     
    3030#ifdef ZOO_SERVICE
    3131#include "service.h"
     32#include "service_internal.h"
    3233#endif
    3334#include "gdal.h"
     
    6162 
    6263  hDataset = GDALOpen( pszFilename, GA_ReadOnly );
     64  free(pszFilename);
    6365  if( hDataset != NULL )
    6466    {
     
    99101          length+=strlen(buffer);
    100102          for(k=0;k<nbGeom;k++){
    101             OGRGeometryH point;
     103            //OGRGeometryH point;
    102104            double prx,pry,prz;
    103105            OGR_G_GetPoint(geometry,k,&prx,&pry,&prz);
    104106            float *pafScanline;
    105          
    106107            pafScanline = (float *) CPLMalloc(sizeof(float));
    107108            int px=(int)floor((prx-adfGeoTransform[0])/adfGeoTransform[1]);
     
    115116                sprintf(tmp,"GDALRasterIO failed for point (%d,%d)",px,py);
    116117                setMapInMaps(conf,"lenv","message",_ss(tmp));
     118                CPLFree(pafScanline);
     119                free(tmp);
    117120                return SERVICE_FAILED;
    118121              }
    119               if(buffer)
    120                 buffer=(char*)realloc(buffer,(strlen(buffer)+50+1)*sizeof(char));
     122              if(buffer!=NULL){
     123                int len=strlen(buffer);
     124                buffer=(char*)realloc(buffer,(len+50+1)*sizeof(char));
     125              }
    121126              else
    122127                buffer=(char*)malloc((51)*sizeof(char));
    123128              char *tmpValue=(char *)malloc(50*sizeof(char));
    124129              sprintf(tmpValue,"[%.6f,%.6f,%.6f]%c",prx,pry,pafScanline[0],(k+1==nbGeom?' ':','));
    125               memcpy(buffer+length,tmpValue,strlen(tmpValue));
     130              strncpy(buffer+length,tmpValue,strlen(tmpValue));
    126131              length+=strlen(tmpValue);
     132              buffer[length]=0;
    127133              value=pafScanline[0];
     134              free(tmpValue);
    128135              //Usefull if we can export 3D JSON string at the end
    129136              //OGR_G_SetPoint(geometry,k,prx,pry,pafScanline[0]);           
    130137            }
    131138            else{
    132               if(buffer)
     139              if(buffer!=NULL)
    133140                buffer=(char*)realloc(buffer,(strlen(buffer)+50+1)*sizeof(char));
    134141              else
     
    136143              char *tmpValue=(char *)malloc(50*sizeof(char));
    137144              sprintf(tmpValue,"[%.6f,%.6f,%.6f]%c",prx,pry,value,(k+1==nbGeom?' ':','));
    138               memcpy(buffer+length,tmpValue,strlen(tmpValue));
     145              strncpy(buffer+length,tmpValue,strlen(tmpValue));
    139146              length+=strlen(tmpValue);
     147              buffer[length]=0;
     148              free(tmpValue);
    140149              value=value;
    141150            }
     151            CPLFree(pafScanline);
    142152            ppx=px;
    143153            ppy=py;
     
    146156          char *tmpValue=(char *)malloc(3*sizeof(char));
    147157          sprintf(tmpValue,"]}");
    148           memcpy(buffer+length,tmpValue,strlen(tmpValue));
     158          tmpValue[2]=0;
     159          strncpy(buffer+length,tmpValue,strlen(tmpValue));
     160          length+=strlen(tmpValue);
     161          buffer[length]=0;
    149162#ifdef ZOO_SERVICE
    150163          setMapInMaps(outputs,"Profile","value",buffer);
     
    153166          fprintf(stderr,"%s\n",buffer);
    154167#endif
     168          free(buffer);
     169          free(tmpValue);
     170          OGR_G_DestroyGeometry(geometry);
    155171        }
    156172    }
     
    163179#endif
    164180  }
    165  
     181  OGRCleanupAll();
    166182  GDALClose(hDataset);
     183  GDALDestroyDriverManager();
    167184#ifdef ZOO_SERVICE
    168185  return SERVICE_SUCCEEDED;
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png