Index: /issm/trunk-jpl/src/c/objects/Numerics/ElementMatrix.cpp
===================================================================
--- /issm/trunk-jpl/src/c/objects/Numerics/ElementMatrix.cpp	(revision 12440)
+++ /issm/trunk-jpl/src/c/objects/Numerics/ElementMatrix.cpp	(revision 12441)
@@ -78,5 +78,5 @@
 
 	/*Initialize itransformation matrix Ke[P[i]] = Ke2[i]*/
-	P=(int*)xmalloc(Ke2->nrows*sizeof(int));
+	P=xNew<int>(Ke2->nrows);
 
 	/*1: Get the new numbering of Ke2 and get size of the new matrix*/
@@ -100,6 +100,6 @@
 
 	/*Gset and values*/
-	this->gglobaldoflist=(int*)xmalloc(this->nrows*sizeof(int));
-	this->values=(double*)xcalloc(this->nrows*this->ncols,sizeof(double));
+	this->gglobaldoflist=xNew<int>(this->nrows);
+	this->values=xNewInit<double>(this->nrows*this->ncols,0.0);
 	for(i=0;i<Ke1->nrows;i++){
 		for(j=0;j<Ke1->ncols;j++){
@@ -122,6 +122,6 @@
 	this->row_fsize=fsize;
 	if(fsize){
-		this->row_flocaldoflist =(int*)xmalloc(fsize*sizeof(int));
-		this->row_fglobaldoflist=(int*)xmalloc(fsize*sizeof(int));
+		this->row_flocaldoflist =xNew<int>(fsize);
+		this->row_fglobaldoflist=xNew<int>(fsize);
 		for(i=0;i<Ke1->row_fsize;i++){
 			this->row_flocaldoflist[i] =Ke1->row_flocaldoflist[i];
@@ -149,6 +149,6 @@
 	this->row_ssize=ssize;
 	if(ssize){
-		this->row_slocaldoflist =(int*)xmalloc(ssize*sizeof(int));
-		this->row_sglobaldoflist=(int*)xmalloc(ssize*sizeof(int));
+		this->row_slocaldoflist =xNew<int>(ssize);
+		this->row_sglobaldoflist=xNew<int>(ssize);
 		for(i=0;i<Ke1->row_ssize;i++){
 			this->row_slocaldoflist[i] =Ke1->row_slocaldoflist[i];
@@ -178,5 +178,5 @@
 
 	/*clean-up*/
-	xfree((void**)&P);
+	xDelete<int>(P);
 }
 /*}}}*/
@@ -205,5 +205,5 @@
 
 	/*fill values with 0: */
-	this->values=(double*)xcalloc(this->nrows*this->ncols,sizeof(double));
+	this->values=xNewInit<double>(this->nrows*this->ncols,0.0);
 
 	/*g list*/
@@ -231,14 +231,14 @@
 ElementMatrix::~ElementMatrix(){
 	
-	xfree((void**)&this->values);
-	xfree((void**)&this->gglobaldoflist);
-	xfree((void**)&this->row_flocaldoflist);
-	xfree((void**)&this->row_fglobaldoflist);
-	xfree((void**)&this->row_slocaldoflist);
-	xfree((void**)&this->row_sglobaldoflist);
-	xfree((void**)&this->col_flocaldoflist);
-	xfree((void**)&this->col_fglobaldoflist);
-	xfree((void**)&this->col_slocaldoflist);
-	xfree((void**)&this->col_sglobaldoflist);
+	xDelete<double>(this->values);
+	xDelete<int>(this->gglobaldoflist);
+	xDelete<int>(this->row_flocaldoflist);
+	xDelete<int>(this->row_fglobaldoflist);
+	xDelete<int>(this->row_slocaldoflist);
+	xDelete<int>(this->row_sglobaldoflist);
+	xDelete<int>(this->col_flocaldoflist);
+	xDelete<int>(this->col_fglobaldoflist);
+	xDelete<int>(this->col_slocaldoflist);
+	xDelete<int>(this->col_sglobaldoflist);
 }
 /*}}}*/
@@ -265,5 +265,5 @@
 		if(this->row_fsize){
 			/*first, retrieve values that are in the f-set from the g-set values matrix: */
-			localvalues=(double*)xmalloc(this->row_fsize*this->row_fsize*sizeof(double));
+			localvalues=xNew<double>(this->row_fsize*this->row_fsize);
 			for(i=0;i<this->row_fsize;i++){
 				for(j=0;j<this->row_fsize;j++){
@@ -275,5 +275,5 @@
 
 			/*Free ressources:*/
-			xfree((void**)&localvalues);
+			xDelete<double>(localvalues);
 		}
 
@@ -281,5 +281,5 @@
 		if((this->row_ssize!=0) && (this->row_fsize!=0)){
 			/*first, retrieve values that are in the f and s-set from the g-set values matrix: */
-			localvalues=(double*)xmalloc(this->row_fsize*this->row_ssize*sizeof(double));
+			localvalues=xNew<double>(this->row_fsize*this->row_ssize);
 			for(i=0;i<this->row_fsize;i++){
 				for(j=0;j<this->row_ssize;j++){
@@ -291,5 +291,5 @@
 
 			/*Free ressources:*/
-			xfree((void**)&localvalues);
+			xDelete<double>(localvalues);
 		}
 	}
@@ -317,5 +317,5 @@
 		if(this->row_fsize){
 			/*first, retrieve values that are in the f-set from the g-set values matrix: */
-			localvalues=(double*)xmalloc(this->row_fsize*this->row_fsize*sizeof(double));
+			localvalues=xNew<double>(this->row_fsize*this->row_fsize);
 			for(i=0;i<this->row_fsize;i++){
 				for(j=0;j<this->row_fsize;j++){
@@ -327,5 +327,5 @@
 
 			/*Free ressources:*/
-			xfree((void**)&localvalues);
+			xDelete<double>(localvalues);
 		}
 
@@ -428,15 +428,15 @@
 	this->dofsymmetrical=Ke->dofsymmetrical;
 
-	this->values=(double*)xmalloc(this->nrows*this->ncols*sizeof(double));
+	this->values=xNew<double>(this->nrows*this->ncols);
 	memcpy(this->values,Ke->values,this->nrows*this->ncols*sizeof(double));
 
-	this->gglobaldoflist=(int*)xmalloc(this->nrows*sizeof(int));
+	this->gglobaldoflist=xNew<int>(this->nrows);
 	memcpy(this->gglobaldoflist,Ke->gglobaldoflist,this->nrows*sizeof(int));
 
 	this->row_fsize=Ke->row_fsize;
 	if(this->row_fsize){
-		this->row_flocaldoflist=(int*)xmalloc(this->row_fsize*sizeof(int));
+		this->row_flocaldoflist=xNew<int>(this->row_fsize);
 		memcpy(this->row_flocaldoflist,Ke->row_flocaldoflist,this->row_fsize*sizeof(int));
-		this->row_fglobaldoflist=(int*)xmalloc(this->row_fsize*sizeof(int));
+		this->row_fglobaldoflist=xNew<int>(this->row_fsize);
 		memcpy(this->row_fglobaldoflist,Ke->row_fglobaldoflist,this->row_fsize*sizeof(int));
 	}
@@ -448,7 +448,7 @@
 	this->row_ssize=Ke->row_ssize;
 	if(this->row_ssize){
-		this->row_slocaldoflist=(int*)xmalloc(this->row_ssize*sizeof(int));
+		this->row_slocaldoflist=xNew<int>(this->row_ssize);
 		memcpy(this->row_slocaldoflist,Ke->row_slocaldoflist,this->row_ssize*sizeof(int));
-		this->row_sglobaldoflist=(int*)xmalloc(this->row_ssize*sizeof(int));
+		this->row_sglobaldoflist=xNew<int>(this->row_ssize);
 		memcpy(this->row_sglobaldoflist,Ke->row_sglobaldoflist,this->row_ssize*sizeof(int));
 	}
@@ -460,7 +460,7 @@
 	this->col_fsize=Ke->col_fsize;
 	if(this->col_fsize){
-		this->col_flocaldoflist=(int*)xmalloc(this->col_fsize*sizeof(int));
+		this->col_flocaldoflist=xNew<int>(this->col_fsize);
 		memcpy(this->col_flocaldoflist,Ke->col_flocaldoflist,this->col_fsize*sizeof(int));
-		this->col_fglobaldoflist=(int*)xmalloc(this->col_fsize*sizeof(int));
+		this->col_fglobaldoflist=xNew<int>(this->col_fsize);
 		memcpy(this->col_fglobaldoflist,Ke->col_fglobaldoflist,this->col_fsize*sizeof(int));
 	}
@@ -472,7 +472,7 @@
 	this->col_ssize=Ke->col_ssize;
 	if(this->col_ssize){
-		this->col_slocaldoflist=(int*)xmalloc(this->col_ssize*sizeof(int));
+		this->col_slocaldoflist=xNew<int>(this->col_ssize);
 		memcpy(this->col_slocaldoflist,Ke->col_slocaldoflist,this->col_ssize*sizeof(int));
-		this->col_sglobaldoflist=(int*)xmalloc(this->col_ssize*sizeof(int));
+		this->col_sglobaldoflist=xNew<int>(this->col_ssize);
 		memcpy(this->col_sglobaldoflist,Ke->col_sglobaldoflist,this->col_ssize*sizeof(int));
 	}
Index: /issm/trunk-jpl/src/c/objects/Numerics/ElementVector.cpp
===================================================================
--- /issm/trunk-jpl/src/c/objects/Numerics/ElementVector.cpp	(revision 12440)
+++ /issm/trunk-jpl/src/c/objects/Numerics/ElementVector.cpp	(revision 12441)
@@ -54,5 +54,5 @@
 
 	/*Initialize itransformation matrix pe[P[i]] = pe2[i]*/
-	P=(int*)xmalloc(pe2->nrows*sizeof(int));
+	P=xNew<int>(pe2->nrows);
 
 	/*1: Get the new numbering of pe2 and get size of the new matrix*/
@@ -74,6 +74,6 @@
 
 	/*Gset and values*/
-	this->gglobaldoflist=(int*)xmalloc(this->nrows*sizeof(int));
-	this->values=(double*)xcalloc(this->nrows,sizeof(double));
+	this->gglobaldoflist=xNew<int>(this->nrows);
+	this->values=xNewInit<double>(this->nrows,0.0);
 	for(i=0;i<pe1->nrows;i++){
 		this->values[i] += pe1->values[i];
@@ -92,6 +92,6 @@
 	this->fsize=fsize;
 	if(fsize){
-		this->flocaldoflist =(int*)xmalloc(fsize*sizeof(int));
-		this->fglobaldoflist=(int*)xmalloc(fsize*sizeof(int));
+		this->flocaldoflist =xNew<int>(fsize);
+		this->fglobaldoflist=xNew<int>(fsize);
 		for(i=0;i<pe1->fsize;i++){
 			this->flocaldoflist[i] =pe1->flocaldoflist[i];
@@ -113,5 +113,5 @@
 
 	/*clean-up*/
-	xfree((void**)&P);
+	xDelete<int>(P);
 }
 /*}}}*/
@@ -138,5 +138,5 @@
 
 	/*fill values with 0: */
-	this->values=(double*)xcalloc(this->nrows,sizeof(double));
+	this->values=xNewInit<double>(this->nrows,0.0);
 	
 	/*g list*/
@@ -152,8 +152,8 @@
 ElementVector::~ElementVector(){
 	
-	xfree((void**)&this->values);
-	xfree((void**)&this->gglobaldoflist);
-	xfree((void**)&this->flocaldoflist);
-	xfree((void**)&this->fglobaldoflist);
+	xDelete<double>(this->values);
+	xDelete<int>(this->gglobaldoflist);
+	xDelete<int>(this->flocaldoflist);
+	xDelete<int>(this->fglobaldoflist);
 }
 /*}}}*/
@@ -171,5 +171,5 @@
 	if(this->fsize){
 		/*first, retrieve values that are in the f-set from the g-set values vector: */
-		localvalues=(double*)xmalloc(this->fsize*sizeof(double));
+		localvalues=xNew<double>(this->fsize);
 		for(i=0;i<this->fsize;i++){
 			localvalues[i]=this->values[this->flocaldoflist[i]];
@@ -179,5 +179,5 @@
 
 		/*Free ressources:*/
-		xfree((void**)&localvalues);
+		xDelete<double>(localvalues);
 	}
 	
@@ -192,5 +192,5 @@
 	if(this->fsize){
 		/*first, retrieve values that are in the f-set from the g-set values vector: */
-		localvalues=(double*)xmalloc(this->fsize*sizeof(double));
+		localvalues=xNew<double>(this->fsize);
 		for(i=0;i<this->fsize;i++){
 			localvalues[i]=this->values[this->flocaldoflist[i]];
@@ -200,5 +200,5 @@
 
 		/*Free ressources:*/
-		xfree((void**)&localvalues);
+		xDelete<double>(localvalues);
 	}
 
@@ -245,15 +245,15 @@
 	this->nrows =pe->nrows;
 
-	this->values=(double*)xmalloc(this->nrows*sizeof(double));
+	this->values=xNew<double>(this->nrows);
 	memcpy(this->values,pe->values,this->nrows*sizeof(double));
 
-	this->gglobaldoflist=(int*)xmalloc(this->nrows*sizeof(int));
+	this->gglobaldoflist=xNew<int>(this->nrows);
 	memcpy(this->gglobaldoflist,pe->gglobaldoflist,this->nrows*sizeof(int));
 
 	this->fsize=pe->fsize;
 	if(this->fsize){
-		this->flocaldoflist=(int*)xmalloc(this->fsize*sizeof(int));
+		this->flocaldoflist=xNew<int>(this->fsize);
 		memcpy(this->flocaldoflist,pe->flocaldoflist,this->fsize*sizeof(int));
-		this->fglobaldoflist=(int*)xmalloc(this->fsize*sizeof(int));
+		this->fglobaldoflist=xNew<int>(this->fsize);
 		memcpy(this->fglobaldoflist,pe->fglobaldoflist,this->fsize*sizeof(int));
 	}
Index: /issm/trunk-jpl/src/c/objects/Numerics/Matrix.cpp
===================================================================
--- /issm/trunk-jpl/src/c/objects/Numerics/Matrix.cpp	(revision 12440)
+++ /issm/trunk-jpl/src/c/objects/Numerics/Matrix.cpp	(revision 12441)
@@ -45,5 +45,5 @@
 	#endif
 	#ifdef _HAVE_ADOLC_
-	this->amatrix=(adouble*)xmalloc(M*N*sizeof(adouble));
+	this->amatrix=xNew<adouble>(M*N);
 	#endif
 }
@@ -58,5 +58,5 @@
 	#endif
 	#ifdef _HAVE_ADOLC_
-	this->amatrix=(adouble*)xmalloc(M*N*sizeof(adouble));
+	this->amatrix=xNew<adouble>;
 	#endif
 }
@@ -69,6 +69,6 @@
 
 
-	int* idxm=(int*)xmalloc(M*sizeof(int));
-	int* idxn=(int*)xmalloc(N*sizeof(int));
+	int* idxm=xNew<int>(M);
+	int* idxn=xNew<int>(N);
 	for(i=0;i<M;i++)idxm[i]=i;
 	for(i=0;i<N;i++)idxn[i]=i;
@@ -79,11 +79,11 @@
 	MatAssemblyEnd(this->matrix,MAT_FINAL_ASSEMBLY);
 
-	xfree((void**)&idxm);
-	xfree((void**)&idxn);
+	xDelete<int>(idxm);
+	xDelete<int>(idxn);
 	#else
 	this->matrix=new SeqMat(serial_mat,M,N,sparsity);
 	#endif
 	#ifdef _HAVE_ADOLC_
-	this->amatrix=(adouble*)xmalloc(M*N*sizeof(adouble));
+	this->amatrix=xNew<adouble>(M*N);
 	#endif
 }
@@ -98,5 +98,5 @@
 	#endif
 	#ifdef _HAVE_ADOLC_
-	this->amatrix=(adouble*)xmalloc(M*N*sizeof(adouble));
+	this->amatrix=xNew<adouble>(M*N);
 	#endif
 }
@@ -111,5 +111,5 @@
 	#endif
 	#ifdef _HAVE_ADOLC_
-	xfree((void**)&this->amatrix);
+	xDelete<adouble>(this->amatrix);
 	#endif
 }
Index: /issm/trunk-jpl/src/c/objects/Numerics/Vector.cpp
===================================================================
--- /issm/trunk-jpl/src/c/objects/Numerics/Vector.cpp	(revision 12440)
+++ /issm/trunk-jpl/src/c/objects/Numerics/Vector.cpp	(revision 12441)
@@ -44,5 +44,5 @@
 	#endif
 	#ifdef _HAVE_ADOLC_
-	this->avector=(adouble*)xmalloc(pM*sizeof(adouble));
+	this->avector=xNew<adouble>(pM);
 	#endif
 }
@@ -52,5 +52,5 @@
 
 	#ifdef _HAVE_PETSC_
-		int* idxm=(int*)xmalloc(M*sizeof(int));
+		int* idxm=xNew<int>(M);
 		for(int i=0;i<M;i++) idxm[i]=i;
 
@@ -60,10 +60,10 @@
 		VecAssemblyEnd(this->vector);
 
-		xfree((void**)&idxm);
+		xDelete<int>(idxm);
 	#else
 		this->vector=new SeqVec(serial_vec,M);
 	#endif
 	#ifdef _HAVE_ADOLC_
-		this->avector=(adouble*)xmalloc(M*sizeof(adouble));
+		this->avector=xNew<adouble>(M);
 	#endif
 }
@@ -109,5 +109,5 @@
 	#endif
 	#ifdef _HAVE_ADOLC_
-	xfree((void**)&this->avector);
+	xDelete<adouble>(this->avector);
 	#endif
 }
Index: /issm/trunk-jpl/src/c/shared/Matrix/MatrixUtils.cpp
===================================================================
--- /issm/trunk-jpl/src/c/shared/Matrix/MatrixUtils.cpp	(revision 12440)
+++ /issm/trunk-jpl/src/c/shared/Matrix/MatrixUtils.cpp	(revision 12441)
@@ -188,5 +188,6 @@
 	ncol=nrow;
 	det=1.;
-	pivrc =(int(*)[2])xNew<int>(nrow*2);
+	pivrc1 =xNew<int>(nrow);
+	pivrc2 =xNew<int>(nrow);
 	pindx =xNew<int>(nrow);
 
@@ -210,5 +211,6 @@
 
 		if (fabs(pivot) < DBL_EPSILON) {
-			xfree((void**)&pivrc);
+			xDelete<int>(pivrc1);
+			xDelete<int>(pivrc2);
 			xDelete<int>(pindx);
 			_error_("Pivot %f less than machine epsilon",pivot);
@@ -325,8 +327,7 @@
 	}
 
-	if (pdet)
-		*pdet=det;
-
-	xfree((void**)&pivrc);
+	if (pdet) *pdet=det;
+	xDelete<int>(pivrc1);
+	xDelete<int>(pivrc2);
 	xDelete<int>(pindx);
 	return noerr;
