Index: trunk/zoo-services/gdal/profile/cgi-env/GdalExtractProfile.zcfg
===================================================================
--- trunk/zoo-services/gdal/profile/cgi-env/GdalExtractProfile.zcfg	(revision 83)
+++ trunk/zoo-services/gdal/profile/cgi-env/GdalExtractProfile.zcfg	(revision 102)
@@ -7,5 +7,5 @@
  serviceType = C
  serviceProvider = gdal_profile_service.zo
- <MetaData>
+ <MetaData lang="en">
    title = My Demo
  </MetaData>
@@ -21,6 +21,4 @@
      value = topofr.tif
     </Default>
-    <Supported>
-    </Supported>
    </LiteralData>
   [Geometry]
Index: trunk/zoo-services/gdal/profile/service.c
===================================================================
--- trunk/zoo-services/gdal/profile/service.c	(revision 83)
+++ trunk/zoo-services/gdal/profile/service.c	(revision 102)
@@ -7,5 +7,5 @@
  *
  * ****************************************************************************
- * Copyright (c) 2010, GeoLabs SARL
+ * Copyright (c) 2010-2011, GeoLabs SARL
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -30,4 +30,5 @@
 #ifdef ZOO_SERVICE
 #include "service.h"
+#include "service_internal.h"
 #endif
 #include "gdal.h"
@@ -61,4 +62,5 @@
  
   hDataset = GDALOpen( pszFilename, GA_ReadOnly );
+  free(pszFilename);
   if( hDataset != NULL )
     {
@@ -99,9 +101,8 @@
 	  length+=strlen(buffer);
 	  for(k=0;k<nbGeom;k++){
-	    OGRGeometryH point;
+	    //OGRGeometryH point;
 	    double prx,pry,prz;
 	    OGR_G_GetPoint(geometry,k,&prx,&pry,&prz);
 	    float *pafScanline;
-	  
 	    pafScanline = (float *) CPLMalloc(sizeof(float));
 	    int px=(int)floor((prx-adfGeoTransform[0])/adfGeoTransform[1]);
@@ -115,20 +116,26 @@
 		sprintf(tmp,"GDALRasterIO failed for point (%d,%d)",px,py);
 		setMapInMaps(conf,"lenv","message",_ss(tmp));
+		CPLFree(pafScanline);
+		free(tmp);
 		return SERVICE_FAILED;
 	      }
-	      if(buffer)
-		buffer=(char*)realloc(buffer,(strlen(buffer)+50+1)*sizeof(char));
+	      if(buffer!=NULL){
+		int len=strlen(buffer);
+		buffer=(char*)realloc(buffer,(len+50+1)*sizeof(char));
+	      }
 	      else
 		buffer=(char*)malloc((51)*sizeof(char));
 	      char *tmpValue=(char *)malloc(50*sizeof(char));
 	      sprintf(tmpValue,"[%.6f,%.6f,%.6f]%c",prx,pry,pafScanline[0],(k+1==nbGeom?' ':','));
-	      memcpy(buffer+length,tmpValue,strlen(tmpValue));
+	      strncpy(buffer+length,tmpValue,strlen(tmpValue));
 	      length+=strlen(tmpValue);
+	      buffer[length]=0;
 	      value=pafScanline[0];
+	      free(tmpValue);
 	      //Usefull if we can export 3D JSON string at the end
 	      //OGR_G_SetPoint(geometry,k,prx,pry,pafScanline[0]);	      
 	    }
 	    else{
-	      if(buffer)
+	      if(buffer!=NULL)
 		buffer=(char*)realloc(buffer,(strlen(buffer)+50+1)*sizeof(char));
 	      else
@@ -136,8 +143,11 @@
 	      char *tmpValue=(char *)malloc(50*sizeof(char));
 	      sprintf(tmpValue,"[%.6f,%.6f,%.6f]%c",prx,pry,value,(k+1==nbGeom?' ':','));
-	      memcpy(buffer+length,tmpValue,strlen(tmpValue));
+	      strncpy(buffer+length,tmpValue,strlen(tmpValue));
 	      length+=strlen(tmpValue);
+	      buffer[length]=0;
+	      free(tmpValue);
 	      value=value;
 	    }
+	    CPLFree(pafScanline);
 	    ppx=px;
 	    ppy=py;
@@ -146,5 +156,8 @@
 	  char *tmpValue=(char *)malloc(3*sizeof(char));
 	  sprintf(tmpValue,"]}");
-	  memcpy(buffer+length,tmpValue,strlen(tmpValue));
+	  tmpValue[2]=0;
+	  strncpy(buffer+length,tmpValue,strlen(tmpValue));
+	  length+=strlen(tmpValue);
+	  buffer[length]=0;
 #ifdef ZOO_SERVICE
 	  setMapInMaps(outputs,"Profile","value",buffer);
@@ -153,4 +166,7 @@
 	  fprintf(stderr,"%s\n",buffer);
 #endif
+	  free(buffer);
+	  free(tmpValue);
+	  OGR_G_DestroyGeometry(geometry);
 	}
     }
@@ -163,6 +179,7 @@
 #endif
   }
-  
+  OGRCleanupAll();
   GDALClose(hDataset);
+  GDALDestroyDriverManager();
 #ifdef ZOO_SERVICE
   return SERVICE_SUCCEEDED;
