Index: /issm/trunk-jpl/src/modules/Chaco/Chaco.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/Chaco/Chaco.cpp	(revision 13037)
+++ /issm/trunk-jpl/src/modules/Chaco/Chaco.cpp	(revision 13038)
@@ -54,14 +54,14 @@
 	nvtxs = mxGetN(A_IN);
 	mwstart = mxGetJc(A_IN);
-	start=(int*)xmalloc((nvtxs+1)*sizeof(int));
+	start=xNew<int>((nvtxs+1));
 	for (i=0; i<nvtxs+1;i++)start[i]=(int)mwstart[i];
 
 	mwadjacency = mxGetIr(A_IN);
-	adjacency = (int*)xmalloc(mxGetNzmax(A_IN)*sizeof(int));
+	adjacency = xNew<int>(mxGetNzmax(A_IN));
 	for (i=0; i<mxGetNzmax(A_IN); i++) adjacency[i]= (int)mwadjacency[i];
 
 	nedges = start[nvtxs];
 	if(!mxIsEmpty(EWGTS_IN)){
-		ewgts = (float*)xcalloc(nedges, sizeof(float));
+		ewgts = xNewZeroInit<float>(nedges);
 		doublepointer=mxGetPr(A_IN);
 		for (i = 0; i < nedges; i++)ewgts[i] = (float)doublepointer[i];
@@ -77,5 +77,5 @@
 	for (i=0;i<(nterms<10?nterms:10);i++) options[i]=in_options[i]; //copy in_options into default options
 	FetchData(&npart,NPARTS_IN); 
-	nparts=(int*)xmalloc(sizeof(int)); nparts[0]=npart; //weird Chacox interface ain't it?
+	nparts=xNew<int>(1); nparts[0]=npart; //weird Chacox interface ain't it?
 	FetchData(&goal,&nterms,GOAL_IN); 
 	
@@ -104,5 +104,5 @@
 	
 	/*Allocate output: */
-	assignment = (short*)xcalloc(nvtxs, sizeof(short));
+	assignment = xNewZeroInit<short>(nvtxs);
 	
     /*Call core: */
@@ -110,5 +110,5 @@
 
     /*Output data: */
-	doubleassignment=(double*)xmalloc(nvtxs*sizeof(double));
+	doubleassignment=xNew<double>(nvtxs);
 	for(i=0;i<nvtxs;i++) doubleassignment[i]=(double)assignment[i];
 	WriteData(ASSGN_OUT,doubleassignment,nvtxs);
Index: /issm/trunk-jpl/src/modules/ContourToNodes/ContourToNodes.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/ContourToNodes/ContourToNodes.cpp	(revision 13037)
+++ /issm/trunk-jpl/src/modules/ContourToNodes/ContourToNodes.cpp	(revision 13038)
@@ -68,8 +68,8 @@
 
 	numcontours=mxGetNumberOfElements(matlabstructure);
-	contours=(Contour**)xmalloc(numcontours*sizeof(Contour*));
+	contours=xNew<Contour*>(numcontours);
 	for(i=0;i<numcontours;i++){
 		//allocate
-		contouri=(Contour*)xmalloc(sizeof(Contour));
+		contouri=xNew<Contour>(1);
 		//retrieve dimension of this contour.
 		contouri->nods=(int)mxGetScalar(mxGetField(matlabstructure,i,"nods"));
Index: /issm/trunk-jpl/src/modules/InternalFront/InternalFront.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/InternalFront/InternalFront.cpp	(revision 13037)
+++ /issm/trunk-jpl/src/modules/InternalFront/InternalFront.cpp	(revision 13038)
@@ -36,5 +36,5 @@
 	/*Allocate and initialize all variables*/
 	numberofsegments=0;
-	front=(int*)xmalloc(3*numberofelements*4*sizeof(int));
+	front=xNew<int>(3*numberofelements*4);
 
 	/*Loop over all elements on water*/
@@ -81,5 +81,5 @@
 	/*Now that we know how many segments there is we can allocate the final matrix*/
 	if(numberofsegments){
-		front2=(double*)xmalloc(4*numberofsegments*sizeof(double));
+		front2=xNew<double>(4*numberofsegments);
 		for(i=0;i<4*numberofsegments;i++) front2[i]=(double)front[i];
 	}
Index: /issm/trunk-jpl/src/modules/InterpFromMesh2d/InterpFromMesh2d.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/InterpFromMesh2d/InterpFromMesh2d.cpp	(revision 13037)
+++ /issm/trunk-jpl/src/modules/InterpFromMesh2d/InterpFromMesh2d.cpp	(revision 13038)
@@ -100,8 +100,8 @@
 		/*contours: */
 		numcontours=mxGetNumberOfElements(matlabstructure);
-		contours=(Contour**)xmalloc(numcontours*sizeof(Contour*));
+		contours=xNew<Contour*>(numcontours);
 		for(i=0;i<numcontours;i++){
 			//allocate
-			contouri=(Contour*)xmalloc(sizeof(Contour));
+			contouri=xNew<Contour>(1);
 			//retrieve dimension of this contour.
 			contouri->nods=(int)mxGetScalar(mxGetField(matlabstructure,i,"nods"));
Index: /issm/trunk-jpl/src/modules/KMLMeshWrite/KMLMeshWrite.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/KMLMeshWrite/KMLMeshWrite.cpp	(revision 13037)
+++ /issm/trunk-jpl/src/modules/KMLMeshWrite/KMLMeshWrite.cpp	(revision 13038)
@@ -55,5 +55,5 @@
 			if (notesi && mxIsChar(notesi) && mxGetNumberOfElements(notesi)) {
 				if (!notes) {
-					notes=(char *) xmalloc((mxGetNumberOfElements(notesi)+1)*sizeof(char));
+					notes=xNew<char>(mxGetNumberOfElements(notesi)+1);
 					mxGetString(notesi,notes,mxGetNumberOfElements(notesi)+1);
 				}
Index: /issm/trunk-jpl/src/modules/MeshPartition/MeshPartition.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/MeshPartition/MeshPartition.cpp	(revision 13037)
+++ /issm/trunk-jpl/src/modules/MeshPartition/MeshPartition.cpp	(revision 13038)
@@ -74,10 +74,10 @@
 
 	/*Post process node_partitioning and element_partitioning to be in double format. Metis needed them in int* format: */
-	element_partitioning=(double*)xmalloc(numberofelements*sizeof(double));
+	element_partitioning=xNew<double>(numberofelements);
 	for (i=0;i<numberofelements;i++){
 		element_partitioning[i]=(double)int_element_partitioning[i]+1; //Metis indexing from 0, matlab from 1.
 	}
 	
-	node_partitioning=(double*)xmalloc(numberofvertices*sizeof(double));
+	node_partitioning=xNew<double>(numberofvertices);
 	for (i=0;i<numberofvertices;i++){
 		node_partitioning[i]=(double)int_node_partitioning[i]+1; //Metis indexing from 0, matlab from 1.
Index: /issm/trunk-jpl/src/modules/MeshProfileIntersection/MeshProfileIntersection.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/MeshProfileIntersection/MeshProfileIntersection.cpp	(revision 13037)
+++ /issm/trunk-jpl/src/modules/MeshProfileIntersection/MeshProfileIntersection.cpp	(revision 13038)
@@ -55,5 +55,5 @@
 	FetchData(&double_index,&nel,&dummy,INDEX);
 	if(dummy!=3 && dummy!=6)_error_("element triangulation should be of 3 or 6 column width!");
-	index=(int*)xmalloc(nel*3*sizeof(int));
+	index=xNew<int>(nel*3);
 	for(i=0;i<nel;i++){
 		for(j=0;j<3;j++){
@@ -67,8 +67,8 @@
 	//contours
 	numcontours=mxGetNumberOfElements(matlabstructure);
-	contours=(Contour**)xmalloc(numcontours*sizeof(Contour*));
+	contours=xNew<Contour*>(numcontours);
 	for(i=0;i<numcontours;i++){
 		//allocate
-		contouri=(Contour*)xmalloc(sizeof(Contour));
+		contouri=xNew<Contour>(1);
 		//retrieve dimension of this contour.
 		contouri->nods=(int)mxGetScalar(mxGetField(matlabstructure,i,"nods"));
Index: /issm/trunk-jpl/src/modules/TriMeshProcessRifts/TriMeshProcessRifts.cpp
===================================================================
--- /issm/trunk-jpl/src/modules/TriMeshProcessRifts/TriMeshProcessRifts.cpp	(revision 13037)
+++ /issm/trunk-jpl/src/modules/TriMeshProcessRifts/TriMeshProcessRifts.cpp	(revision 13038)
@@ -73,5 +73,5 @@
 		nel=mxGetM(prhs[0]);
 		tindex_in=mxGetPr(prhs[0]);
-		index_in=(double*)xmalloc(nel*3*sizeof(double));
+		index_in=xNew<double>(nel*3);
 		for (i=0;i<nel;i++){
 			for (j=0;j<3;j++){
@@ -88,5 +88,5 @@
 		nods=mxGetM(prhs[1]);
 		x_inm=mxGetPr(prhs[1]);
-		x_in=(double*)xmalloc(nods*sizeof(double));
+		x_in=xNew<double>(nods);
 		for (i=0;i<nods;i++){
 			x_in[i]=x_inm[i];
@@ -100,5 +100,5 @@
 	if(mxIsDouble(prhs[2])){
 		y_inm=mxGetPr(prhs[2]);
-		y_in=(double*)xmalloc(nods*sizeof(double));
+		y_in=xNew<double>(nods);
 		for (i=0;i<nods;i++){
 			y_in[i]=y_inm[i];
@@ -113,5 +113,5 @@
 		num_seg=mxGetM(prhs[3]);
 		tsegments_in=mxGetPr(prhs[3]);
-		segments_in=(double*)xmalloc(num_seg*3*sizeof(double));
+		segments_in=xNew<double>(num_seg*3);
 		for (i=0;i<num_seg;i++){
 			for (j=0;j<3;j++){
@@ -127,5 +127,5 @@
 	if(mxIsDouble(prhs[4])){
 		tsegmentmarkers_in=mxGetPr(prhs[4]);
-		segmentmarkers_in=(double*)xmalloc(num_seg*sizeof(double));
+		segmentmarkers_in=xNew<double>(num_seg);
 		for (i=0;i<num_seg;i++){
 			segmentmarkers_in[i]=tsegmentmarkers_in[i];
