From 6a2eabde098db6461efa4eb00ec4bad174836de2 Mon Sep 17 00:00:00 2001 From: bangerth Date: Wed, 17 Nov 2010 03:05:53 +0000 Subject: [PATCH] Make sure we don't run into a weird error with double deallocation of memory. git-svn-id: https://svn.dealii.org/trunk@22782 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/examples/step-40/step-40.cc | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/deal.II/examples/step-40/step-40.cc b/deal.II/examples/step-40/step-40.cc index fbdcf5c0a3..e77a3e1fef 100644 --- a/deal.II/examples/step-40/step-40.cc +++ b/deal.II/examples/step-40/step-40.cc @@ -877,16 +877,34 @@ void LaplaceProblem::run () // inialize and finalize PETSc, which // also initializes and finalizes the // MPI subsystem. + // + // Note how we enclose the use the + // use of the LaplaceProblem class in + // a pair of braces. This makes sure + // that all member variables of the + // object are destroyed by the time + // we hit the + // PetscFinalize + // call. Not doing this will lead to + // strange and hard to debug errors + // when PetscFinalize + // first deletes all PETSc vectors + // that are still around, and the + // destructor of the LaplaceProblem + // class then tries to delete them + // again. int main(int argc, char *argv[]) { try { PetscInitialize(&argc, &argv, PETSC_NULL, PETSC_NULL); deallog.depth_console (0); - - LaplaceProblem<2> laplace_problem_2d; - laplace_problem_2d.run (); - + + { + LaplaceProblem<2> laplace_problem_2d; + laplace_problem_2d.run (); + } + PetscFinalize(); } catch (std::exception &exc) -- 2.39.5