From: heister Date: Mon, 5 Aug 2013 22:07:43 +0000 (+0000) Subject: fix some of the PETSc memory leaks X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=608793a50782f116ac9e4c58a1fe43601bc82e2f;p=dealii-svn.git fix some of the PETSc memory leaks git-svn-id: https://svn.dealii.org/trunk@30231 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/include/deal.II/lac/petsc_parallel_vector.h b/deal.II/include/deal.II/lac/petsc_parallel_vector.h index 0c0cf8ae63..bc3ee07627 100644 --- a/deal.II/include/deal.II/lac/petsc_parallel_vector.h +++ b/deal.II/include/deal.II/lac/petsc_parallel_vector.h @@ -594,9 +594,17 @@ namespace PETScWrappers // Vector x,v;x=v; // we skip the code below and create a simple serial vector of // length 0 + + int ierr; +#if DEAL_II_PETSC_VERSION_LT(3,2,0) + ierr = VecDestroy (vector); +#else + ierr = VecDestroy (&vector); +#endif + AssertThrow (ierr == 0, ExcPETScError(ierr)); + const int n = 0; - const int ierr - = VecCreateSeq (PETSC_COMM_SELF, n, &vector); + ierr = VecCreateSeq (PETSC_COMM_SELF, n, &vector); AssertThrow (ierr == 0, ExcPETScError(ierr)); ghosted = false; ghost_indices.clear(); diff --git a/deal.II/source/lac/petsc_parallel_vector.cc b/deal.II/source/lac/petsc_parallel_vector.cc index 9aeafe4839..848ba3eec1 100644 --- a/deal.II/source/lac/petsc_parallel_vector.cc +++ b/deal.II/source/lac/petsc_parallel_vector.cc @@ -194,6 +194,14 @@ namespace PETScWrappers const IndexSet &ghost, const MPI_Comm &comm) { + int ierr; +#if DEAL_II_PETSC_VERSION_LT(3,2,0) + ierr = VecDestroy (vector); +#else + ierr = VecDestroy (&vector); +#endif + AssertThrow (ierr == 0, ExcPETScError(ierr)); + communicator = comm; Assert(local.is_contiguous(), ExcNotImplemented()); @@ -215,6 +223,14 @@ namespace PETScWrappers Vector::reinit (const IndexSet &local, const MPI_Comm &comm) { + int ierr; +#if DEAL_II_PETSC_VERSION_LT(3,2,0) + ierr = VecDestroy (vector); +#else + ierr = VecDestroy (&vector); +#endif + AssertThrow (ierr == 0, ExcPETScError(ierr)); + communicator = comm; Assert(local.is_contiguous(), ExcNotImplemented());