Index: /issm/trunk-jpl/src/c/bamg/Mesh.cpp
===================================================================
--- /issm/trunk-jpl/src/c/bamg/Mesh.cpp	(revision 18452)
+++ /issm/trunk-jpl/src/c/bamg/Mesh.cpp	(revision 18453)
@@ -227,20 +227,20 @@
 		/*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, Mesh2.cpp/Triangles)*/
 
-		//if (vertices)             delete [] vertices;
-		if (edges)                delete [] edges;
-		if (triangles)            delete [] triangles;
-		if (quadtree)             delete    quadtree;
-		//if (orderedvertices)                delete [] orderedvertices;
-		if (subdomains)           delete []  subdomains;
-		if (VerticesOnGeomEdge)   delete [] VerticesOnGeomEdge;
-		if (VerticesOnGeomVertex) delete [] VerticesOnGeomVertex;
-		if (VertexOnBThVertex)    delete [] VertexOnBThVertex;
-		if (VertexOnBThEdge)      delete [] VertexOnBThEdge;
-
-		if (&Gh) {
+		if(vertices)             delete [] vertices;
+		if(edges)                delete [] edges;
+		if(triangles)            delete [] triangles;
+		if(quadtree)             delete    quadtree;
+		if(orderedvertices)      delete [] orderedvertices;
+		if(subdomains)           delete []  subdomains;
+		if(VerticesOnGeomEdge)   delete [] VerticesOnGeomEdge;
+		if(VerticesOnGeomVertex) delete [] VerticesOnGeomVertex;
+		if(VertexOnBThVertex)    delete [] VertexOnBThVertex;
+		if(VertexOnBThEdge)      delete [] VertexOnBThEdge;
+
+		if(&Gh){
 			if (Gh.NbRef>0) Gh.NbRef--;
 			else if (Gh.NbRef==0) delete &Gh;
 		}
-		if (&BTh && (&BTh != this)) {
+		if(&BTh && (&BTh != this)){
 			if (BTh.NbRef>0) BTh.NbRef--;
 			else if (BTh.NbRef==0) delete &BTh;
@@ -2726,5 +2726,5 @@
 
 		/*Allocate if maxnbv_in>0*/
-		if (maxnbv_in) {
+		if(maxnbv_in){
 			vertices=new BamgVertex[maxnbv];
 			_assert_(vertices);
@@ -2734,5 +2734,5 @@
 			_assert_(triangles);
 		}
-		else {
+		else{
 			vertices=NULL;
 			orderedvertices=NULL;
Index: /issm/trunk-jpl/src/c/modules/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp	(revision 18452)
+++ /issm/trunk-jpl/src/c/modules/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp	(revision 18453)
@@ -49,10 +49,10 @@
 
 	/*read background mesh*/
-	Mesh Th(index_data,x_data,y_data,nods_data,nels_data); 
+	Mesh* Th=new Mesh(index_data,x_data,y_data,nods_data,nels_data); 
 
 	/*Get reference number (for subdomains)*/
-	long* reft = xNew<long>(Th.nbt);
-	Th.TriangleReferenceList(reft);
-	Th.CreateSingleVertexToTriangleConnectivity();
+	long* reft = xNew<long>(Th->nbt);
+	Th->TriangleReferenceList(reft);
+	Th->CreateSingleVertexToTriangleConnectivity();
 
 	/*Get domain boundaries*/
@@ -79,8 +79,8 @@
 		/*Get current point coordinates*/
 		r.x=x_interp[i]; r.y=y_interp[i];
-		I2 I=Th.R2ToI2(r);
+		I2 I=Th->R2ToI2(r);
 
 		/*Find triangle holding r/I*/
-		Triangle &tb=*Th.TriangleFindFromCoord(I,dete);
+		Triangle &tb=*Th->TriangleFindFromCoord(I,dete);
 
 		/*point inside convex*/
@@ -92,9 +92,9 @@
 			areacoord[2]= (double) dete[2]/tb.det;
 			/*3 vertices of the triangle*/
-			i0=Th.GetId(tb[0]);
-			i1=Th.GetId(tb[1]);
-			i2=Th.GetId(tb[2]);
+			i0=Th->GetId(tb[0]);
+			i1=Th->GetId(tb[1]);
+			i2=Th->GetId(tb[2]);
 			/*triangle number*/
-			it=Th.GetId(tb);
+			it=Th->GetId(tb);
 
 			/*Inside convex but outside mesh*/
@@ -120,9 +120,9 @@
 				areacoord[OppositeVertex[k]] = 1 - aa -bb;
 				//3 vertices of the triangle
-				i0=Th.GetId(tc[0]);
-				i1=Th.GetId(tc[1]);
-				i2=Th.GetId(tc[2]);
+				i0=Th->GetId(tc[0]);
+				i1=Th->GetId(tc[1]);
+				i2=Th->GetId(tc[2]);
 				//triangle number
-				it=Th.GetId(tc);
+				it=Th->GetId(tc);
 			}
 		}
@@ -145,4 +145,5 @@
 
 	/*clean-up and return*/
+	delete Th;
 	xDelete<long>(reft);
 	*pdata_interp=data_interp;
Index: /issm/trunk-jpl/src/wrappers/InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.cpp	(revision 18452)
+++ /issm/trunk-jpl/src/wrappers/InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.cpp	(revision 18453)
@@ -76,4 +76,12 @@
 
 	/*end module: */
+	xDelete<int>(index);
+	xDelete<double>(x_data);
+	xDelete<double>(y_data);
+	xDelete<double>(data);
+	xDelete<double>(x_interp);
+	xDelete<double>(y_interp);
+	xDelete<double>(data_interp);
+	delete options;
 	MODULEEND();
 }
Index: /issm/trunk-jpl/src/wrappers/python/io/WritePythonData.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/python/io/WritePythonData.cpp	(revision 18452)
+++ /issm/trunk-jpl/src/wrappers/python/io/WritePythonData.cpp	(revision 18453)
@@ -35,7 +35,11 @@
 	PyObject* array=NULL;
 
-	dims[0]=(npy_intp)M;
-	dims[1]=(npy_intp)N;
-	array=PyArray_SimpleNewFromData(2,dims,NPY_DOUBLE,matrix);
+	/*copy matrix: */
+	double* matrix_python=xNew<double>(M*N);
+	memcpy(matrix_python,matrix,M*N*sizeof(double));
+
+	dims[0]=(npy_intp)M;
+	dims[1]=(npy_intp)N;
+	array=PyArray_SimpleNewFromData(2,dims,NPY_DOUBLE,matrix_python);
 
 	PyTuple_SetItem(tuple, index, array);
@@ -47,11 +51,7 @@
 	PyObject* array=NULL;
 
-	/*intermediary:*/
-	long* lmatrix=NULL;
-	int i;
-
 	/*transform into long matrix: */
-	lmatrix=xNew<long>(M*N);
-	for(i=0;i<M*N;i++)lmatrix[i]=(long)matrix[i];
+	long* lmatrix=xNew<long>(M*N);
+	for(int i=0;i<M*N;i++)lmatrix[i]=(long)matrix[i];
 
 	dims[0]=(npy_intp)M;
@@ -67,7 +67,11 @@
 	PyObject* array=NULL;
 
-	dims[0]=(npy_intp)M;
-	dims[1]=(npy_intp)N;
-	array=PyArray_SimpleNewFromData(2,dims,NPY_BOOL,matrix);
+	/*copy matrix: */
+	bool* matrix_python=xNew<bool>(M*N);
+	memcpy(matrix_python,matrix,M*N*sizeof(bool));
+
+	dims[0]=(npy_intp)M;
+	dims[1]=(npy_intp)N;
+	array=PyArray_SimpleNewFromData(2,dims,NPY_BOOL,matrix_python);
 
 	PyTuple_SetItem(tuple, index, array);
@@ -76,14 +80,14 @@
 void WriteData(PyObject* py_tuple, int index, double* vector, int M){
 
-	double   *buffer = NULL;
 	npy_intp  dim   = 10;
 	PyObject *array = NULL;
 
-	/*Copy vector*/
-	buffer=xNew<double>(M);
-	for(int i=0;i<M;i++)buffer[i]=vector[i];
+
+	/*copy vector: */
+	double* vector_python=xNew<double>(M);
+	memcpy(vector_python,vector,M*sizeof(double));
 
 	dim=(npy_intp)M;
-	array=PyArray_SimpleNewFromData(1,&dim,NPY_DOUBLE,buffer);
+	array=PyArray_SimpleNewFromData(1,&dim,NPY_DOUBLE,vector_python);
 
 	PyTuple_SetItem(py_tuple, index, array);
