From 9ebb278f4d7a3cea80a7b0e6d1fe24c9f19fbc33 Mon Sep 17 00:00:00 2001 From: bangerth Date: Wed, 5 Nov 2008 23:20:44 +0000 Subject: [PATCH] Prevent a memory leak in the block matrix base class. git-svn-id: https://svn.dealii.org/trunk@17481 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 10 +++++++++- deal.II/lac/include/lac/block_matrix_base.h | 8 ++++++-- deal.II/lac/source/trilinos_block_sparse_matrix.cc | 3 +++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 30edd5512c..5586bff1fe 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -322,6 +322,15 @@ inconvenience this causes.

lac

    +
  1. +

    + Fixed: The BlockMatrixBase::clear() function that is used by all other + block matrix type classes had a memory leak in that the memory + allocated by all sub-objects was not freed. This is now fixed. +
    + (WB 2008/11/05) +

    +
  2. New: The function SparsityTools::reorder_Cuthill_McKee reorders @@ -330,7 +339,6 @@ inconvenience this causes. (WB 2008/10/31)

    -
  3. New: The function GridTools::get_face_connectivity_of_cells produces a diff --git a/deal.II/lac/include/lac/block_matrix_base.h b/deal.II/lac/include/lac/block_matrix_base.h index 11f81f5494..fe842cbff7 100644 --- a/deal.II/lac/include/lac/block_matrix_base.h +++ b/deal.II/lac/include/lac/block_matrix_base.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2004, 2005, 2006, 2007 by the deal.II authors +// Copyright (C) 2004, 2005, 2006, 2007, 2008 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -1470,7 +1470,11 @@ BlockMatrixBase::clear () { for (unsigned int r=0; rsub_objects[r][c]; + this->sub_objects[r][c] = 0; + delete p; + } sub_objects.reinit (0,0); // reset block indices to empty diff --git a/deal.II/lac/source/trilinos_block_sparse_matrix.cc b/deal.II/lac/source/trilinos_block_sparse_matrix.cc index 2faa07ecd7..4fbee6fd4f 100644 --- a/deal.II/lac/source/trilinos_block_sparse_matrix.cc +++ b/deal.II/lac/source/trilinos_block_sparse_matrix.cc @@ -93,6 +93,9 @@ namespace TrilinosWrappers for (unsigned int c=0; cn_block_cols(); ++c) { BlockType *p = new BlockType(); + + Assert (this->sub_objects[r][c] == 0, + ExcInternalError()); this->sub_objects[r][c] = p; } } -- 2.39.5