From: Wolfgang Bangerth Date: Fri, 11 Nov 2016 00:39:40 +0000 (-0700) Subject: Fix a memory leak in de-serializing a SparsityPattern object. X-Git-Tag: v8.5.0-rc1~417^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f717532999a1979e1be430b19157dae97c22424e;p=dealii.git Fix a memory leak in de-serializing a SparsityPattern object. --- 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);