From 0bae228912561ffa7929a4d12fa247d294603499 Mon Sep 17 00:00:00 2001 From: heister Date: Mon, 5 Aug 2013 22:41:29 +0000 Subject: [PATCH] add destructor to PETScWrappers::MPI::SparseMatrix to not leak memory git-svn-id: https://svn.dealii.org/trunk@30233 0785d39b-7218-0410-832d-ea1e28bc413d --- .../include/deal.II/lac/petsc_parallel_sparse_matrix.h | 5 +++++ deal.II/source/lac/petsc_parallel_sparse_matrix.cc | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/deal.II/include/deal.II/lac/petsc_parallel_sparse_matrix.h b/deal.II/include/deal.II/lac/petsc_parallel_sparse_matrix.h index 6bfa4df7dd..115bb94bfc 100644 --- a/deal.II/include/deal.II/lac/petsc_parallel_sparse_matrix.h +++ b/deal.II/include/deal.II/lac/petsc_parallel_sparse_matrix.h @@ -158,6 +158,11 @@ namespace PETScWrappers */ SparseMatrix (); + /** + * Destructor to free the PETSc object. + */ + ~SparseMatrix (); + /** * Create a sparse matrix of * dimensions @p m times @p n, with diff --git a/deal.II/source/lac/petsc_parallel_sparse_matrix.cc b/deal.II/source/lac/petsc_parallel_sparse_matrix.cc index e366b66458..6e91035df7 100644 --- a/deal.II/source/lac/petsc_parallel_sparse_matrix.cc +++ b/deal.II/source/lac/petsc_parallel_sparse_matrix.cc @@ -43,6 +43,14 @@ namespace PETScWrappers } + SparseMatrix::~SparseMatrix () + { +#if DEAL_II_PETSC_VERSION_LT(3,2,0) + const int ierr = MatDestroy (matrix); +#else + const int ierr = MatDestroy (&matrix); +#endif + } SparseMatrix::SparseMatrix (const MPI_Comm &communicator, const size_type m, -- 2.39.5