[cig-commits] r21791 - short/3D/PyLith/trunk/libsrc/pylith/topology

brad at geodynamics.org brad at geodynamics.org
Wed Apr 10 08:43:21 PDT 2013


Author: brad
Date: 2013-04-10 08:43:20 -0700 (Wed, 10 Apr 2013)
New Revision: 21791

Modified:
   short/3D/PyLith/trunk/libsrc/pylith/topology/Field.cc
   short/3D/PyLith/trunk/libsrc/pylith/topology/Makefile.am
   short/3D/PyLith/trunk/libsrc/pylith/topology/SubMesh.icc
Log:
Fixed memory leaks.

Modified: short/3D/PyLith/trunk/libsrc/pylith/topology/Field.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/Field.cc	2013-04-10 13:15:07 UTC (rev 21790)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/Field.cc	2013-04-10 15:43:20 UTC (rev 21791)
@@ -34,7 +34,10 @@
 // Default constructor.
 template<typename mesh_type>
 pylith::topology::Field<mesh_type>::Field(const mesh_type& mesh) :
-  _mesh(mesh)
+  _mesh(mesh),
+  _dm(NULL),
+  _globalVec(NULL),
+  _localVec(NULL)
 { // constructor
   PYLITH_METHOD_BEGIN;
 
@@ -43,11 +46,12 @@
   _metadata["default"].scale = 1.0;
   _metadata["default"].dimsOkay = false;
   if (mesh.dmMesh()) {
-    PetscDM dm = mesh.dmMesh();
+    PetscDM dm = mesh.dmMesh();assert(dm);
     PetscVec coordVec = NULL;
     PetscSection s = NULL;
     PetscErrorCode err;
 
+    err = DMDestroy(&_dm);CHECK_PETSC_ERROR(err);
     err = DMPlexClone(dm, &_dm);CHECK_PETSC_ERROR(err);
     err = DMGetCoordinatesLocal(dm, &coordVec);CHECK_PETSC_ERROR(err);
     if (coordVec) {
@@ -61,15 +65,11 @@
       err = DMSetDefaultSection(newCoordDM, newCoordSection);CHECK_PETSC_ERROR(err);
       err = PetscSectionDestroy(&newCoordSection);CHECK_PETSC_ERROR(err);
       err = DMSetCoordinatesLocal(_dm, coordVec);CHECK_PETSC_ERROR(err);
-    }
+    } // if
     err = PetscSectionCreate(mesh.comm(), &s);CHECK_PETSC_ERROR(err);
     err = DMSetDefaultSection(_dm, s);CHECK_PETSC_ERROR(err);
     err = PetscSectionDestroy(&s);CHECK_PETSC_ERROR(err);
-  } else {
-    _dm = NULL;
-  }
-  _globalVec = NULL;
-  _localVec  = NULL;
+  } // if
 
   PYLITH_METHOD_END;
 } // constructor
@@ -81,7 +81,9 @@
 					  PetscDM dm,
 					  const Metadata& metadata) :
   _mesh(mesh),
-  _dm(dm)
+  _dm(dm),
+  _globalVec(NULL),
+  _localVec(NULL)
 { // constructor
   PYLITH_METHOD_BEGIN;
 
@@ -105,7 +107,9 @@
 					  PetscVec localVec,
 					  const Metadata& metadata) :
   _mesh(mesh),
-  _dm(dm)
+  _dm(dm),
+  _globalVec(NULL),
+  _localVec(NULL)
 { // constructor
   PYLITH_METHOD_BEGIN;
 
@@ -130,7 +134,10 @@
 pylith::topology::Field<mesh_type>::Field(const Field& src,
 					  const int fields[],
 					  int numFields) :
-  _mesh(src._mesh)
+  _mesh(src._mesh),
+  _dm(NULL),
+  _globalVec(NULL),
+  _localVec(NULL)
 { // constructor
   PYLITH_METHOD_BEGIN;
 
@@ -162,8 +169,6 @@
     err = PetscSectionDestroy(&newCoordSection);CHECK_PETSC_ERROR(err);
     err = DMSetCoordinatesLocal(_dm, coordVec);CHECK_PETSC_ERROR(err);
   } // if
-  _globalVec = NULL;
-  _localVec  = NULL;
 
   PYLITH_METHOD_END;
 } // constructor
@@ -512,7 +517,9 @@
   err = PetscSectionClone(section, &newSection);CHECK_PETSC_ERROR(err);
   err = DMSetDefaultSection(_dm, newSection);CHECK_PETSC_ERROR(err);
   err = PetscSectionDestroy(&newSection);CHECK_PETSC_ERROR(err);
+  err = VecDestroy(&_globalVec);CHECK_PETSC_ERROR(err);
   err = DMCreateGlobalVector(_dm, &_globalVec);CHECK_PETSC_ERROR(err);
+  err = VecDestroy(&_localVec);CHECK_PETSC_ERROR(err);
   err = DMCreateLocalVector(_dm, &_localVec);CHECK_PETSC_ERROR(err);
   err = PetscObjectSetName((PetscObject) _globalVec, _metadata["default"].label.c_str());CHECK_PETSC_ERROR(err);
   err = PetscObjectSetName((PetscObject) _localVec,  _metadata["default"].label.c_str());CHECK_PETSC_ERROR(err);
@@ -605,7 +612,9 @@
   assert(s);
 
   err = PetscSectionSetUp(s);CHECK_PETSC_ERROR(err);
+  err = VecDestroy(&_globalVec);CHECK_PETSC_ERROR(err);
   err = DMCreateGlobalVector(_dm, &_globalVec);CHECK_PETSC_ERROR(err);
+  err = VecDestroy(&_localVec);CHECK_PETSC_ERROR(err);
   err = DMCreateLocalVector(_dm, &_localVec);CHECK_PETSC_ERROR(err);
   err = PetscObjectSetName((PetscObject) _globalVec, _metadata["default"].label.c_str());CHECK_PETSC_ERROR(err);
   err = PetscObjectSetName((PetscObject) _localVec,  _metadata["default"].label.c_str());CHECK_PETSC_ERROR(err);
@@ -1067,6 +1076,7 @@
   PetscSection section, newSection, gsection;
   PetscSF      sf;
 
+  err = DMDestroy(&sinfo.dm);CHECK_PETSC_ERROR(err);
   err = DMPlexClone(_dm, &sinfo.dm);CHECK_PETSC_ERROR(err);
   err = DMGetDefaultSection(_dm, &section);CHECK_PETSC_ERROR(err);
   err = PetscSectionClone(section, &newSection);CHECK_PETSC_ERROR(err);
@@ -1076,6 +1086,7 @@
   err = PetscSectionCreateGlobalSection(section, sf, PETSC_TRUE, &gsection);CHECK_PETSC_ERROR(err);
   err = DMSetDefaultGlobalSection(sinfo.dm, gsection);CHECK_PETSC_ERROR(err);
   err = PetscSectionDestroy(&gsection);CHECK_PETSC_ERROR(err);
+  err = VecDestroy(&sinfo.vector);CHECK_PETSC_ERROR(err);
   err = DMCreateGlobalVector(sinfo.dm, &sinfo.vector);CHECK_PETSC_ERROR(err);
   err = PetscObjectSetName((PetscObject) sinfo.vector, _metadata["default"].label.c_str());CHECK_PETSC_ERROR(err);
   PetscInt localSize, globalSize;
@@ -1169,6 +1180,7 @@
     numExcludes = 0;
   } // if
 
+  err = DMDestroy(&sinfo.dm);CHECK_PETSC_ERROR(err);
   err = DMPlexClone(_dm, &sinfo.dm);CHECK_PETSC_ERROR(err);
   err = PetscSectionClone(section, &newSection);CHECK_PETSC_ERROR(err);
   err = DMSetDefaultSection(sinfo.dm, newSection);CHECK_PETSC_ERROR(err);
@@ -1187,6 +1199,7 @@
   } // if
   err = DMSetDefaultGlobalSection(sinfo.dm, gsection);CHECK_PETSC_ERROR(err);
   err = PetscSectionDestroy(&gsection);CHECK_PETSC_ERROR(err);
+  err = VecDestroy(&sinfo.vector);CHECK_PETSC_ERROR(err);
   err = DMCreateGlobalVector(sinfo.dm, &sinfo.vector);CHECK_PETSC_ERROR(err);
   err = PetscObjectSetName((PetscObject) sinfo.vector, _metadata["default"].label.c_str());CHECK_PETSC_ERROR(err);
   PetscInt localSize, globalSize;

Modified: short/3D/PyLith/trunk/libsrc/pylith/topology/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/Makefile.am	2013-04-10 13:15:07 UTC (rev 21790)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/Makefile.am	2013-04-10 15:43:20 UTC (rev 21791)
@@ -33,7 +33,6 @@
 	Mesh.hh \
 	Mesh.icc \
 	MeshOps.hh \
-	RefineUniform.hh \
 	ReverseCuthillMcKee.hh \
 	SolutionFields.hh \
 	Stratum.hh \
@@ -47,20 +46,22 @@
 	VisitorSubMesh.icc \
 	topologyfwd.hh
 
+
 noinst_HEADERS =
 
 # TEMPORARY
-noinst_HEADERS += \
-	MeshRefiner.hh \
-	MeshRefiner.cc \
-	RefineEdges2.hh \
-	CellRefinerTri3.hh \
-	CellRefinerTet4.hh \
-	RefineFace4Edges2.hh \
-	CellRefinerQuad4.hh \
-	RefineVol8Face4Edges2.hh \
-	CellRefinerHex8.hh \
-	MeshOrder.hh
+#noinst_HEADERS += \
+#	RefineUniform.hh
+#	MeshRefiner.hh \
+#	MeshRefiner.cc \
+#	RefineEdges2.hh \
+#	CellRefinerTri3.hh \
+#	CellRefinerTet4.hh \
+#	RefineFace4Edges2.hh \
+#	CellRefinerQuad4.hh \
+#	RefineVol8Face4Edges2.hh \
+#	CellRefinerHex8.hh \
+#	MeshOrder.hh
 
 
 # End of file 

Modified: short/3D/PyLith/trunk/libsrc/pylith/topology/SubMesh.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/pylith/topology/SubMesh.icc	2013-04-10 13:15:07 UTC (rev 21790)
+++ short/3D/PyLith/trunk/libsrc/pylith/topology/SubMesh.icc	2013-04-10 15:43:20 UTC (rev 21791)
@@ -146,7 +146,7 @@
 inline
 const MPI_Comm
 pylith::topology::SubMesh::comm(void) const {
-  MPI_Comm comm = NULL;
+  MPI_Comm comm;
   if (_newMesh) {
     PetscErrorCode err = PetscObjectGetComm((PetscObject)_newMesh, &comm);
   } // if



More information about the CIG-COMMITS mailing list