From f717532999a1979e1be430b19157dae97c22424e Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Thu, 10 Nov 2016 17:39:40 -0700 Subject: [PATCH] Fix a memory leak in de-serializing a SparsityPattern object. --- doc/news/changes.h | 7 +++++++ include/deal.II/lac/sparsity_pattern.h | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/doc/news/changes.h b/doc/news/changes.h index cefa9106e0..b4e8ea63bc 100644 --- a/doc/news/changes.h +++ b/doc/news/changes.h @@ -437,6 +437,13 @@ inconvenience this causes.

Specific improvements

    +
  1. Fixed: There was a memory leak if a previously used SparsityPattern + object was re-used by reading from a serialization archive via + SparsityPattern::load(). This is now fixed. +
    + (Wolfgang Bangerth, 2016/11/10) +
  2. +
  3. New: Add PArpackSolver::reinit(const VectorType &distributed_vector) to initialize internal data structures based on a vector. This makes PArpack usable with MatrixFree operators. diff --git a/include/deal.II/lac/sparsity_pattern.h b/include/deal.II/lac/sparsity_pattern.h index ce07d9e127..2db0dd3009 100644 --- a/include/deal.II/lac/sparsity_pattern.h +++ b/include/deal.II/lac/sparsity_pattern.h @@ -1430,8 +1430,13 @@ SparsityPattern::load (Archive &ar, const unsigned int) ar &max_dim &rows &cols &max_vec_len &max_row_length &compressed &store_diagonal_first_in_row; - rowstart = new std::size_t [max_dim + 1]; - colnums = new size_type [max_vec_len]; + if (rowstart != 0) + delete[] rowstart; + rowstart = new std::size_t[max_dim + 1]; + + if (colnums != 0) + delete[] colnums; + colnums = new size_type[max_vec_len]; ar &boost::serialization::make_array(rowstart, max_dim + 1); ar &boost::serialization::make_array(colnums, max_vec_len); -- 2.39.5