Index: issm/trunk-jpl/src/c/modules/Exp2Kmlx/Exp2Kmlx.cpp
===================================================================
--- issm/trunk-jpl/src/c/modules/Exp2Kmlx/Exp2Kmlx.cpp	(revision 12422)
+++ issm/trunk-jpl/src/c/modules/Exp2Kmlx/Exp2Kmlx.cpp	(revision 12442)
@@ -11,29 +11,22 @@
 #include "../modules.h"
 
-int Exp2Kmlx(char* filexp,char* filkml,
-			 int sgn,
-			 bool holes){
+int Exp2Kmlx(char* filexp,char* filkml,int sgn,bool holes){
 
 	double  cm,sp;
 
 	Xy2lldef(&cm,&sp,sgn);
-
-	return(Exp2Kmlx(filexp,filkml,
-					sgn,cm,sp,
-					holes));
+	return(Exp2Kmlx(filexp,filkml,sgn,cm,sp,holes));
 }
 
-int Exp2Kmlx(char* filexp,char* filkml,
-			 int sgn,double cm,double sp,
-			 bool holes){
-
-	int     i,j,iret=0;
-	int     lwidth=1;
-	double  popac=0.50;
-	int     nprof;
-	int     *pnvert=NULL;
-	double  **pprofx=NULL,**pprofy=NULL;
-	bool    *closed=NULL;
-	double  *lat=NULL,*lon=NULL;
+int Exp2Kmlx(char* filexp,char* filkml,int sgn,double cm,double sp,bool holes){
+
+	int      i        ,j,iret=0;
+	int      lwidth = 1;
+	double   popac  = 0.50;
+	int      nprof;
+	int     *pnvert = NULL;
+	double **pprofx = NULL,**pprofy=NULL;
+	bool    *closed = NULL;
+	double  *lat    = NULL, *lon=NULL;
 
 	char    indent[81]="";
@@ -59,5 +52,5 @@
 	_printf_(true,"\nExp2Kmlx Module -- %s",ctime(&time0));
 
-/*  read exp file  */
+	/*read exp file  */
 
 	if (!DomainOutlineRead(&nprof,&pnvert,&pprofx,&pprofy,&closed,filexp))
@@ -143,15 +136,15 @@
 
 		kring->ncoord    =pnvert[i]-1;
-		lat=(double *) xmalloc(kring->ncoord*sizeof(double));
-		lon=(double *) xmalloc(kring->ncoord*sizeof(double));
+		lat=xNew<double>(kring->ncoord);
+		lon=xNew<double>(kring->ncoord);
 		Xy2llx(lat,lon,pprofx[i],pprofy[i],kring->ncoord,sgn,cm,sp);
-		kring->coords    =(double (*)[3]) xmalloc(kring->ncoord*3*sizeof(double));
+		kring->coords=xNew<double>(kring->ncoord*3);
 		for (j=0; j<kring->ncoord; j++) {
-			kring->coords[j][0]=lon[j];
-			kring->coords[j][1]=lat[j];
-			kring->coords[j][2]=0.;
+			kring->coords[3*j+0]=lon[j];
+			kring->coords[3*j+1]=lat[j];
+			kring->coords[3*j+2]=0.;
 		}
-		xfree((void**)&lon);
-		xfree((void**)&lat);
+		xDelete<double>(lon);
+		xDelete<double>(lat);
 
 		(kpoly ->outer     )->AddObject((Object*)kring);
@@ -167,15 +160,15 @@
 
 			kring->ncoord    =pnvert[i]-1;
-			lat=(double *) xmalloc(kring->ncoord*sizeof(double));
-			lon=(double *) xmalloc(kring->ncoord*sizeof(double));
+			lat=xNew<double>(kring->ncoord);
+			lon=xNew<double>(kring->ncoord);
 			Xy2llx(lat,lon,pprofx[i],pprofy[i],kring->ncoord,sgn,cm,sp);
-			kring->coords    =(double (*)[3]) xmalloc(kring->ncoord*3*sizeof(double));
+			kring->coords    =xNew<double>(kring->ncoord*3);
 			for (j=0; j<kring->ncoord; j++) {
-				kring->coords[j][0]=lon[j];
-				kring->coords[j][1]=lat[j];
-				kring->coords[j][2]=0.;
-			}
-			xfree((void**)&lon);
-			xfree((void**)&lat);
+				kring->coords[3*j+0]=lon[j];
+				kring->coords[3*j+1]=lat[j];
+				kring->coords[3*j+2]=0.;
+			}
+			xDelete<double>(lon);
+			xDelete<double>(lat);
 
 			(kpoly ->inner     )->AddObject((Object*)kring);
@@ -204,15 +197,15 @@
 
 				kring->ncoord    =pnvert[i]-1;
-				lat=(double *) xmalloc(kring->ncoord*sizeof(double));
-				lon=(double *) xmalloc(kring->ncoord*sizeof(double));
+				lat=xNew<double>(kring->ncoord);
+				lon=xNew<double>(kring->ncoord);
 				Xy2llx(lat,lon,pprofx[i],pprofy[i],kring->ncoord,sgn,cm,sp);
-				kring->coords    =(double (*)[3]) xmalloc(kring->ncoord*3*sizeof(double));
+				kring->coords    =xNew<double>(kring->ncoord*3);
 				for (j=0; j<kring->ncoord; j++) {
-					kring->coords[j][0]=lon[j];
-					kring->coords[j][1]=lat[j];
-					kring->coords[j][2]=0.;
+					kring->coords[3*j+0]=lon[j];
+					kring->coords[3*j+1]=lat[j];
+					kring->coords[3*j+2]=0.;
 				}
-				xfree((void**)&lon);
-				xfree((void**)&lat);
+				xDelete<double>(lon);
+				xDelete<double>(lat);
 
 				(kpoly ->outer     )->AddObject((Object*)kring);
@@ -231,15 +224,15 @@
 
 				kline->ncoord    =pnvert[i];
-				lat=(double *) xmalloc(kline->ncoord*sizeof(double));
-				lon=(double *) xmalloc(kline->ncoord*sizeof(double));
+				lat=xNew<double>(kline->ncoord);
+				lon=xNew<double>(kline->ncoord);
 				Xy2llx(lat,lon,pprofx[i],pprofy[i],kline->ncoord,sgn,cm,sp);
-				kline->coords    =(double (*)[3]) xmalloc(kline->ncoord*3*sizeof(double));
+				kline->coords    =xNew<double>(kline->ncoord*3);
 				for (j=0; j<kline->ncoord; j++) {
-					kline->coords[j][0]=lon[j];
-					kline->coords[j][1]=lat[j];
-					kline->coords[j][2]=0.;
+					kline->coords[3*j+0]=lon[j];
+					kline->coords[3*j+1]=lat[j];
+					kline->coords[3*j+2]=0.;
 				}
-				xfree((void**)&lon);
-				xfree((void**)&lat);
+				xDelete<double>(lon);
+				xDelete<double>(lat);
 
 				(kplace->geometry  )->AddObject((Object*)kline);
@@ -251,15 +244,16 @@
 				kplace->visibility=true;
 				sprintf(kplace->styleurl  ,"#RandomLineEmptyPoly");
+				int one=1;
 
 				kpoint=new KML_Point();
 
-				lat=(double *) xmalloc(sizeof(double));
-				lon=(double *) xmalloc(sizeof(double));
+				lat=xNew<double>(one);
+				lon=xNew<double>(one);
 				Xy2llx(lat,lon,pprofx[i],pprofy[i],1,sgn,cm,sp);
 				kpoint->coords[0]=lon[0];
 				kpoint->coords[1]=lat[0];
 				kpoint->coords[2]=0.;
-				xfree((void**)&lon);
-				xfree((void**)&lat);
+				xDelete<double>(lon);
+				xDelete<double>(lat);
 
 				(kplace->geometry  )->AddObject((Object*)kpoint);
@@ -289,8 +283,8 @@
 	delete kfile;
 	for (i=nprof-1; i>=0; i--) {
-		xfree((void**)&(pprofy[i]));
-		xfree((void**)&(pprofx[i]));
-	}
-	xfree((void**)&pnvert);
+		xDelete<double>(pprofy[i]);
+		xDelete<double>(pprofx[i]);
+	}
+	xDelete<int>(pnvert);
 
 	clock1=clock();
Index: issm/trunk-jpl/src/c/modules/InterpFromMesh2dx/InterpFromMesh2dx.cpp
===================================================================
--- issm/trunk-jpl/src/c/modules/InterpFromMesh2dx/InterpFromMesh2dx.cpp	(revision 12422)
+++ issm/trunk-jpl/src/c/modules/InterpFromMesh2dx/InterpFromMesh2dx.cpp	(revision 12442)
@@ -84,6 +84,6 @@
 	}
 	else{
-		 incontour=(double*)xmalloc(nods_prime*sizeof(double));
-		 for (i=0;i<nods_prime;i++) incontour[i]=1;
+		 incontour=xNew<double>(nods_prime);
+		 for (i=0;i<nods_prime;i++) incontour[i]=1.0;
 	}
 
@@ -112,5 +112,5 @@
 
 	/*Assign output pointers:*/
-	 xfree((void**)&incontour);
+	 xDelete<double>(incontour);
 	*pdata_prime=data_prime;
 }
Index: issm/trunk-jpl/src/c/modules/IoModelToConstraintsx/IoModelToConstraintsx.cpp
===================================================================
--- issm/trunk-jpl/src/c/modules/IoModelToConstraintsx/IoModelToConstraintsx.cpp	(revision 12422)
+++ issm/trunk-jpl/src/c/modules/IoModelToConstraintsx/IoModelToConstraintsx.cpp	(revision 12442)
@@ -69,5 +69,5 @@
 
 		/*figure out times: */
-		times=(double*)xmalloc(N*sizeof(double));
+		times=xNew<double>(N);
 		for(j=0;j<N;j++){
 			times[j]=doublevector[(M-1)*N+j];
@@ -83,5 +83,5 @@
 
 				/*figure out times and values: */
-				values=(double*)xmalloc(N*sizeof(double));
+				values=xNew<double>(N);
 				spcpresent=false;
 				for(j=0;j<N;j++){
@@ -94,5 +94,5 @@
 					count++;
 				}
-				xfree((void**)&values);
+				xDelete<double>(values);
 			}
 		}
@@ -103,6 +103,6 @@
 
 	/*Free ressources:*/
-	xfree((void**)&doublevector);
-	xfree((void**)&times);
-	xfree((void**)&values);
+	xDelete<double>(doublevector);
+	xDelete<double>(times);
+	xDelete<double>(values);
 }
Index: issm/trunk-jpl/src/c/modules/KMLMeshWritex/KMLMeshWritex.cpp
===================================================================
--- issm/trunk-jpl/src/c/modules/KMLMeshWritex/KMLMeshWritex.cpp	(revision 12422)
+++ issm/trunk-jpl/src/c/modules/KMLMeshWritex/KMLMeshWritex.cpp	(revision 12442)
@@ -9,28 +9,18 @@
 #include "../../EnumDefinitions/EnumDefinitions.h"
 
-void KMLMeshWritex(int* ierror,
-				   char* name,
-				   char* notes,
-				   int* elem,int melem,int nelem,
-				   int* nodecon,int mncon,int nncon,
-				   double* lat, double* lng,
-				   int* part,
-				   double* data, int mdata, int ndata,
-				   double* cmap, int mcmap, int ncmap,
-				   FILE* fid){
-
-	int     i,j,k,ipt=0,jpt=0,nnodes;
-	int     mxepg=25;
-	int     lwidth=1;
-	double  popac=0.50;
-	char    indent[81]="  ";
-	char    cstr[81];
-	double* edata=NULL;
-	bool    ncfree=false,
-			edfree=false;
-	KML_Document*  kdoc=NULL;
-	KML_Style*     kstyle;
-	KML_LineStyle* klsty;
-	KML_PolyStyle* kpsty;
+void KMLMeshWritex(int* ierror,char* name,char* notes,int* elem,int melem,int nelem,int* nodecon,int mncon,int nncon,double* lat, double* lng,int* part,double* data, int mdata, int ndata,double* cmap, int mcmap, int ncmap,FILE* fid){
+
+	int                 i,j,k,ipt=0,jpt=0,nnodes;
+	int                 mxepg      = 25;
+	int                 lwidth     = 1;
+	double              popac      = 0.50;
+	char                indent[81] = " ";
+	char                cstr[81];
+	double             *edata = NULL;
+	bool ncfree=false, edfree=false;
+	KML_Document       *kdoc = NULL;
+	KML_Style          *kstyle;
+	KML_LineStyle      *klsty;
+	KML_PolyStyle      *kpsty;
 
 	clock_t clock0,clock1,clock0a,clock0b,clock0c;
@@ -130,5 +120,5 @@
 		_printf_(true,"Creating the node connectivity table.\n");
 		nncon=mxepg+1;
-		nodecon=(int *) xcalloc(mncon*nncon,sizeof(int));
+		nodecon=xNewInit<int>(mncon*nncon,0);
 		ncfree=true;
 
@@ -160,5 +150,5 @@
 		else if (mdata == mncon) {
 			_printf_(true,"Averaging nodal data to element data.\n");
-			edata=(double *) xcalloc(melem*ndata,sizeof(double));
+			edata=xNewInit<double>(melem*ndata,0);
 			edfree=true;
 
@@ -194,6 +184,6 @@
 														cmap,mcmap,ncmap));
 
-	if (edfree) xfree((void**)&edata);
-	if (ncfree) xfree((void**)&nodecon);
+	if(edfree) xfree((void**)&edata);
+	if(ncfree) xfree((void**)&nodecon);
 	clock0a=clock();
 	time0a =time(NULL);
@@ -344,24 +334,24 @@
 		kring=new KML_LinearRing();
 		kring->ncoord    =nelem+1;
-		kring->coords    =(double (*)[3]) xmalloc((nelem+1)*3*sizeof(double));
+		kring->coords =xNew<double>((nelem+1)*3);
 
 /*  write the nodal coordinates as a linear ring  */
 
 		for (j=0; j<nelem; j++) {
-			kring->coords[j][0]=lng[elem[ipt]-1];
-			kring->coords[j][1]=lat[elem[ipt]-1];
-			kring->coords[j][2]=alt;
+			kring->coords[3*j+0]=lng[elem[ipt]-1];
+			kring->coords[3*j+1]=lat[elem[ipt]-1];
+			kring->coords[3*j+2]=alt;
 			ipt++;
 		}
-		kring->coords[nelem][0]=kring->coords[0][0];
-		kring->coords[nelem][1]=kring->coords[0][1];
-		kring->coords[nelem][2]=kring->coords[0][2];
+		kring->coords[3*nelem+0]=kring->coords[3*0+0];
+		kring->coords[3*nelem+1]=kring->coords[3*0+1];
+		kring->coords[3*nelem+2]=kring->coords[3*0+2];
 //		kring->DeepEcho();
 
 /*  assemble the linear ring into polygon into placemark into folder  */
 
-		(kpoly ->outer     )->AddObject((Object*)kring);
-		(kplace->geometry  )->AddObject((Object*)kpoly);
-		(kfold ->feature   )->AddObject((Object*)kplace);
+		(kpoly ->outer   )->AddObject((Object*)kring);
+		(kplace->geometry)->AddObject((Object*)kpoly);
+		(kfold ->feature )->AddObject((Object*)kplace);
 
 //		if (!(int)fmod((double)(i+1),1000))
Index: issm/trunk-jpl/src/c/modules/Krigingx/pKrigingx.cpp
===================================================================
--- issm/trunk-jpl/src/c/modules/Krigingx/pKrigingx.cpp	(revision 12422)
+++ issm/trunk-jpl/src/c/modules/Krigingx/pKrigingx.cpp	(revision 12442)
@@ -37,6 +37,6 @@
 
 	/*Allocate output*/
-	predictions =(double*)xcalloc(n_interp,sizeof(double));
-	error       =(double*)xcalloc(n_interp,sizeof(double));
+	predictions =xNewInit<double>(n_interp,0.0);
+	error       =xNewInit<double>(n_interp,0.0);
 
 	/*Get output*/
@@ -62,10 +62,10 @@
 
 #ifdef _HAVE_MPI_
-		double *sumpredictions =(double*)xmalloc(n_interp*sizeof(double));
-		double *sumerror       =(double*)xmalloc(n_interp*sizeof(double));
+		double *sumpredictions =xNew<double>(n_interp);
+		double *sumerror       =xNew<double>(n_interp);
 		MPI_Allreduce(predictions,sumpredictions,n_interp,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD);
 		MPI_Allreduce(error,sumerror,n_interp,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD);
-		xfree((void**)&error); error=sumerror;
-		xfree((void**)&predictions); predictions=sumpredictions;
+		xDelete<double>(error); error=sumerror;
+		xDelete<double>(predictions); predictions=sumpredictions;
 #endif
 	}
@@ -80,7 +80,7 @@
 
 #ifdef _HAVE_MPI_
-		double *sumpredictions =(double*)xmalloc(n_interp*sizeof(double));
+		double *sumpredictions =xNew<double>(n_interp);
 		MPI_Allreduce(predictions,sumpredictions,n_interp,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD);
-		xfree((void**)&predictions); predictions=sumpredictions;
+		xDelete<double>(predictions); predictions=sumpredictions;
 #endif
 	}
@@ -97,7 +97,7 @@
 
 #ifdef _HAVE_MPI_
-		double *sumpredictions =(double*)xmalloc(n_interp*sizeof(double));
+		double *sumpredictions =xNew<double>(n_interp);
 		MPI_Allreduce(predictions,sumpredictions,n_interp,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD);
-		xfree((void**)&predictions); predictions=sumpredictions;
+		xDelete<double>(predictions); predictions=sumpredictions;
 #endif
 	}
@@ -109,5 +109,5 @@
 	delete variogram;
 	delete observations;
-	xfree((void**)&output);
+	xDelete<char>(output);
 	*ppredictions = predictions;
 	*perror       = error;
@@ -131,5 +131,5 @@
 
 	/*Assign output pointer*/
-	xfree((void**)&model);
+	xDelete<char>(model);
 	*pvariogram = variogram;
 }/*}}}*/
Index: issm/trunk-jpl/src/c/modules/Shp2Kmlx/Shp2Kmlx.cpp
===================================================================
--- issm/trunk-jpl/src/c/modules/Shp2Kmlx/Shp2Kmlx.cpp	(revision 12422)
+++ issm/trunk-jpl/src/c/modules/Shp2Kmlx/Shp2Kmlx.cpp	(revision 12442)
@@ -39,7 +39,7 @@
 	int     nshape,ncoord;
 	double  cpsum;
-	int     *pstype=NULL,*pnpart=NULL,**ppstrt=NULL,**pptype=NULL,*pnvert=NULL;
-	double  **pshapx=NULL,**pshapy=NULL,**pshapz=NULL,**pshapm=NULL;
-	double  *lat=NULL,*lon=NULL;
+	int     *pstype = NULL, *pnpart=NULL,**ppstrt=NULL,**pptype=NULL,*pnvert=NULL;
+	double **pshapx = NULL,**pshapy=NULL,**pshapz=NULL,**pshapm=NULL;
+	double  *lat    = NULL, *lon=NULL;
 
 	SHPHandle   hSHP;
@@ -49,18 +49,17 @@
 
 	char    indent[81]="";
-	KML_File*             kfile =NULL;
-	KML_Document*         kdoc  =NULL;
-	KML_Style*            kstyle=NULL;
-	KML_LineStyle*        klsty =NULL;
-	KML_PolyStyle*        kpsty =NULL;
-	KML_Folder*           kfold =NULL;
-	KML_Placemark*        kplace=NULL;
-	KML_MultiGeometry*    kmulti=NULL;
-	KML_Polygon*          kpoly =NULL;
-	KML_LinearRing*       kring =NULL;
-	KML_LineString*       kline =NULL;
-	KML_Point*            kpoint=NULL;
-
-	FILE*   fid=NULL;
+	KML_File          *kfile  = NULL;
+	KML_Document      *kdoc   = NULL;
+	KML_Style         *kstyle = NULL;
+	KML_LineStyle     *klsty  = NULL;
+	KML_PolyStyle     *kpsty  = NULL;
+	KML_Folder        *kfold  = NULL;
+	KML_Placemark     *kplace = NULL;
+	KML_MultiGeometry *kmulti = NULL;
+	KML_Polygon       *kpoly  = NULL;
+	KML_LinearRing    *kring  = NULL;
+	KML_LineString    *kline  = NULL;
+	KML_Point         *kpoint = NULL;
+	FILE              *fid    = NULL;
 
 	clock_t clock0,clock1;
@@ -97,13 +96,13 @@
 
 	nshape=nEntities;
-	pstype=(int *) xmalloc(nshape*sizeof(int));
-	pnpart=(int *) xmalloc(nshape*sizeof(int));
-	ppstrt=(int **) xmalloc(nshape*sizeof(int *));
-	pptype=(int **) xmalloc(nshape*sizeof(int *));
-	pnvert=(int *) xmalloc(nshape*sizeof(int));
-	pshapx=(double **) xmalloc(nshape*sizeof(double *));
-	pshapy=(double **) xmalloc(nshape*sizeof(double *));
-	pshapz=(double **) xmalloc(nshape*sizeof(double *));
-	pshapm=(double **) xmalloc(nshape*sizeof(double *));
+	pstype=xNew<int>(nshape);
+	pnpart=xNew<int>(nshape);
+	ppstrt=xNew<int*>(nshape);
+	pptype=xNew<int*>(nshape);
+	pnvert=xNew<int>(nshape);
+	pshapx=xNew<double*>(nshape);
+	pshapy=xNew<double*>(nshape);
+	pshapz=xNew<double*>(nshape);
+	pshapm=xNew<double*>(nshape);
 
 /*  loop over the list of shapes  */
@@ -129,6 +128,6 @@
 	pnpart[i]=psShape->nParts;
 	if (pnpart[i]) {
-		ppstrt[i]=(int *) xmalloc(pnpart[i]*sizeof(int));
-		pptype[i]=(int *) xmalloc(pnpart[i]*sizeof(int));
+		ppstrt[i]=xNew<int>(pnpart[i]);
+		pptype[i]=xNew<int>(pnpart[i]);
 	}
 	else {
@@ -138,8 +137,8 @@
 	pnvert[i]=psShape->nVertices;
 	if (pnvert[i]) {
-		pshapx[i]=(double *) xmalloc(pnvert[i]*sizeof(double));
-		pshapy[i]=(double *) xmalloc(pnvert[i]*sizeof(double));
-		pshapz[i]=(double *) xmalloc(pnvert[i]*sizeof(double));
-		pshapm[i]=(double *) xmalloc(pnvert[i]*sizeof(double));
+		pshapx[i]=xNew<double>(pnvert[i]);
+		pshapy[i]=xNew<double>(pnvert[i]);
+		pshapz[i]=xNew<double>(pnvert[i]);
+		pshapm[i]=xNew<double>(pnvert[i]);
 	}
 	else {
@@ -296,6 +295,6 @@
 			kpoint=new KML_Point();
 
-			lat=(double *) xmalloc(pnvert[i]*sizeof(double));
-			lon=(double *) xmalloc(pnvert[i]*sizeof(double));
+			lat=xNew<double>(pnvert[i]);
+			lon=xNew<double>(pnvert[i]);
 			if (sgn) {
 				Xy2llx(lat,lon,pshapx[i],pshapy[i],pnvert[i],sgn,cm,sp);
@@ -310,6 +309,6 @@
 			kpoint->coords[2]=pshapz[i][0];
 
-			xfree((void**)&lon);
-			xfree((void**)&lat);
+			xDelete<double>(lon);
+			xDelete<double>(lat);
 
 			(kplace->geometry  )->AddObject((Object*)kpoint);
@@ -337,6 +336,6 @@
 /*  convert to lat/lon, if necessary  */
 
-			lat=(double *) xmalloc(pnvert[i]*sizeof(double));
-			lon=(double *) xmalloc(pnvert[i]*sizeof(double));
+			lat=xNew<double>(pnvert[i]);
+			lon=xNew<double>(pnvert[i]);
 			if (sgn) {
 				Xy2llx(lat,lon,pshapx[i],pshapy[i],pnvert[i],sgn,cm,sp);
@@ -353,21 +352,20 @@
 
 				kline->ncoord    =(j<pnpart[i]-1 ? ppstrt[i][j+1]-ppstrt[i][j] : pnvert[i]-ppstrt[i][j]);
-				kline->coords    =(double (*)[3]) xmalloc(kline->ncoord*3*sizeof(double));
+				kline->coords    =xNew<double>(kline->ncoord*3);
 				for (k=0; k<kline->ncoord; k++) {
-					kline->coords[k][0]=lon      [ppstrt[i][j]+k];
-					kline->coords[k][1]=lat      [ppstrt[i][j]+k];
-					kline->coords[k][2]=pshapz[i][ppstrt[i][j]+k];
+					kline->coords[3*k+0]=lon      [ppstrt[i][j]+k];
+					kline->coords[3*k+1]=lat      [ppstrt[i][j]+k];
+					kline->coords[3*k+2]=pshapz[i][ppstrt[i][j]+k];
 				}
-
 				(kmulti->geometry  )->AddObject((Object*)kline);
-				kline =NULL;
-			}
-
-			xfree((void**)&lon);
-			xfree((void**)&lat);
-
-			(kplace->geometry  )->AddObject((Object*)kmulti);
+				kline = NULL;
+			}
+
+			xDelete<double>(lon);
+			xDelete<double>(lat);
+
+			(kplace->geometry)->AddObject((Object*)kmulti);
 			kmulti=NULL;
-			(kfold ->feature   )->AddObject((Object*)kplace);
+			(kfold ->feature )->AddObject((Object*)kplace);
 			kplace=NULL;
 		}
@@ -401,6 +399,6 @@
 /*  convert to lat/lon, if necessary  */
 
-			lat=(double *) xmalloc(pnvert[i]*sizeof(double));
-			lon=(double *) xmalloc(pnvert[i]*sizeof(double));
+			lat=xNew<double>(pnvert[i]);
+			lon=xNew<double>(pnvert[i]);
 			if (sgn) {
 				Xy2llx(lat,lon,pshapx[i],pshapy[i],pnvert[i],sgn,cm,sp);
@@ -438,16 +436,16 @@
 
 					kring->ncoord    =(j<pnpart[i]-1 ? ppstrt[i][j+1]-ppstrt[i][j] : pnvert[i]-ppstrt[i][j]);
-					kring->coords    =(double (*)[3]) xmalloc(kring->ncoord*3*sizeof(double));
+					kring->coords    =xNew<double>(kring->ncoord*3);
 					if (cpsum < 0)
 						for (k=0; k<kring->ncoord; k++) {
-							kring->coords[kring->ncoord-1-k][0]=lon      [ppstrt[i][j]+k];
-							kring->coords[kring->ncoord-1-k][1]=lat      [ppstrt[i][j]+k];
-							kring->coords[kring->ncoord-1-k][2]=pshapz[i][ppstrt[i][j]+k];
+							kring->coords[3*(kring->ncoord-1-k)+0]=lon      [ppstrt[i][j]+k];
+							kring->coords[3*(kring->ncoord-1-k)+1]=lat      [ppstrt[i][j]+k];
+							kring->coords[3*(kring->ncoord-1-k)+2]=pshapz[i][ppstrt[i][j]+k];
 						}
 					else
 						for (k=0; k<kring->ncoord; k++) {
-							kring->coords[k                ][0]=lon      [ppstrt[i][j]+k];
-							kring->coords[k                ][1]=lat      [ppstrt[i][j]+k];
-							kring->coords[k                ][2]=pshapz[i][ppstrt[i][j]+k];
+							kring->coords[3*k+0]=lon      [ppstrt[i][j]+k];
+							kring->coords[3*k+1]=lat      [ppstrt[i][j]+k];
+							kring->coords[3*k+2]=pshapz[i][ppstrt[i][j]+k];
 						}
 
@@ -470,9 +468,9 @@
 
 					kring->ncoord    =(j<pnpart[i]-1 ? ppstrt[i][j+1]-ppstrt[i][j] : pnvert[i]-ppstrt[i][j]);
-					kring->coords    =(double (*)[3]) xmalloc(kring->ncoord*3*sizeof(double));
+					kring->coords    =xNew<double>(kring->ncoord*3);
 					for (k=0; k<kring->ncoord; k++) {
-						kring->coords[k][0]=lon      [ppstrt[i][j]+k];
-						kring->coords[k][1]=lat      [ppstrt[i][j]+k];
-						kring->coords[k][2]=pshapz[i][ppstrt[i][j]+k];
+						kring->coords[3*k+0]=lon      [ppstrt[i][j]+k];
+						kring->coords[3*k+1]=lat      [ppstrt[i][j]+k];
+						kring->coords[3*k+2]=pshapz[i][ppstrt[i][j]+k];
 					}
 
@@ -487,6 +485,6 @@
 			}
 
-			xfree((void**)&lon);
-			xfree((void**)&lat);
+			xDelete<double>(lon);
+			xDelete<double>(lat);
 
 			(kplace->geometry  )->AddObject((Object*)kmulti);
@@ -518,6 +516,6 @@
 /*  convert to lat/lon, if necessary  */
 
-			lat=(double *) xmalloc(pnvert[i]*sizeof(double));
-			lon=(double *) xmalloc(pnvert[i]*sizeof(double));
+			lat=xNew<double>(pnvert[i]);
+			lon=xNew<double>(pnvert[i]);
 			if (sgn) {
 				Xy2llx(lat,lon,pshapx[i],pshapy[i],pnvert[i],sgn,cm,sp);
@@ -541,6 +539,6 @@
 			}
 
-			xfree((void**)&lon);
-			xfree((void**)&lat);
+			xDelete<double>(lon);
+			xDelete<double>(lat);
 
 			(kplace->geometry  )->AddObject((Object*)kmulti);
@@ -583,22 +581,22 @@
 	delete kfile;
 	for (i=nshape-1; i>=0; i--) {
-		xfree((void**)&(pshapm[i]));
-		xfree((void**)&(pshapz[i]));
-		xfree((void**)&(pshapy[i]));
-		xfree((void**)&(pshapx[i]));
-	}
-	xfree((void**)&pshapm);
-	xfree((void**)&pshapz);
-	xfree((void**)&pshapy);
-	xfree((void**)&pshapx);
-	xfree((void**)&pnvert);
+		xDelete<double>((pshapm[i]));
+		xDelete<double>((pshapz[i]));
+		xDelete<double>((pshapy[i]));
+		xDelete<double>((pshapx[i]));
+	}
+	xDelete<double*>(pshapm);
+	xDelete<double*>(pshapz);
+	xDelete<double*>(pshapy);
+	xDelete<double*>(pshapx);
+	xDelete<int>(pnvert);
 	for (i=nshape-1; i>=0; i--) {
-		xfree((void**)&(pptype[i]));
-		xfree((void**)&(ppstrt[i]));
-	}
-	xfree((void**)&pptype);
-	xfree((void**)&ppstrt);
-	xfree((void**)&pnpart);
-	xfree((void**)&pstype);
+		xDelete<int>((pptype[i]));
+		xDelete<int>((ppstrt[i]));
+	}
+	xDelete<int*>(pptype);
+	xDelete<int*>(ppstrt);
+	xDelete<int>(pnpart);
+	xDelete<int>(pstype);
 
 	clock1=clock();
Index: issm/trunk-jpl/src/c/modules/TriMeshx/TriMeshx.cpp
===================================================================
--- issm/trunk-jpl/src/c/modules/TriMeshx/TriMeshx.cpp	(revision 12422)
+++ issm/trunk-jpl/src/c/modules/TriMeshx/TriMeshx.cpp	(revision 12442)
@@ -57,5 +57,5 @@
 
 	/*fill in the point list: */
-	in.pointlist = (REAL *) xmalloc(in.numberofpoints * 2 * sizeof(REAL));
+	in.pointlist = xNew<REAL>(in.numberofpoints*2);
 
 	counter=0;
@@ -78,9 +78,9 @@
 	
 	/*fill in the point attribute list: */
-	in.pointattributelist = (REAL*)xmalloc(in.numberofpoints*in.numberofpointattributes*sizeof(REAL));
+	in.pointattributelist = xNew<REAL>(in.numberofpoints*in.numberofpointattributes);
 	for (i=0;i<in.numberofpoints;i++) in.pointattributelist[i] = 0.0;
 	
 	/*fill in the point marker list: */
-	in.pointmarkerlist = (int *) xmalloc(in.numberofpoints * sizeof(int));
+	in.pointmarkerlist = xNew<int>(in.numberofpoints);
 	for(i=0;i<in.numberofpoints;i++) in.pointmarkerlist[i] = 0;
 
@@ -97,6 +97,6 @@
 	}
 	
-	in.segmentlist = (int *) xmalloc(in.numberofsegments * 2 * sizeof(int));
-	in.segmentmarkerlist = (int *) xcalloc(in.numberofsegments,sizeof(int));
+	in.segmentlist = xNew<int>(in.numberofsegments*2);
+	in.segmentmarkerlist = (int*)xcalloc(in.numberofsegments,sizeof(int));
 	counter=0;
 	backcounter=0;
@@ -135,5 +135,5 @@
 	in.numberofholes = domain->Size()-1; /*everything is a hole, but for the first profile.*/
 	if(in.numberofholes){
-		in.holelist = (REAL *) xmalloc(in.numberofholes * 2 * sizeof(REAL));
+		in.holelist = xNew<REAL>(in.numberofholes*2);
 		for (i=0;i<domain->Size()-1;i++){
 			contour=(Contour*)domain->GetObjectByOffset(i+1);
@@ -164,9 +164,9 @@
 
 	/*Allocate index, x and y: */
-	index=(double*)xmalloc(3*out.numberoftriangles*sizeof(double));
-	x=(double*)xmalloc(out.numberofpoints*sizeof(double));
-	y=(double*)xmalloc(out.numberofpoints*sizeof(double));
-	segments=(double*)xmalloc(3*out.numberofsegments*sizeof(double));
-	segmentmarkerlist=(double*)xmalloc(out.numberofsegments*sizeof(double));
+	index=xNew<double>(3*out.numberoftriangles);
+	x=xNew<double>(out.numberofpoints);
+	y=xNew<double>(out.numberofpoints);
+	segments=xNew<double>(3*out.numberofsegments);
+	segmentmarkerlist=xNew<double>(out.numberofsegments);
 
 	for (i = 0; i< out.numberoftriangles; i++) {
