From 39bc5a57a82c4d31d7374f43906a30c0b8ca1b82 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Sat, 3 Jul 2021 22:40:57 -0600 Subject: [PATCH] Avoid a memory leak in step-34. --- examples/step-34/step-34.cc | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/examples/step-34/step-34.cc b/examples/step-34/step-34.cc index db6d4c55e2..83dfcdde67 100644 --- a/examples/step-34/step-34.cc +++ b/examples/step-34/step-34.cc @@ -212,7 +212,7 @@ namespace Step34 // To allow for dimension independent programming, we specialize this // single function to extract the singular quadrature formula needed to // integrate the singular kernels in the interior of the cells. - const Quadrature &get_singular_quadrature( + Quadrature get_singular_quadrature( const typename DoFHandler::active_cell_iterator &cell, const unsigned int index) const; @@ -661,12 +661,12 @@ namespace Step34 // against a singular weight on the reference cell. // // The correct quadrature formula is selected by the - // get_singular_quadrature function, which is explained in + // `get_singular_quadrature()` function, which is explained in // detail below. Assert(singular_index != numbers::invalid_unsigned_int, ExcInternalError()); - const Quadrature &singular_quadrature = + const Quadrature singular_quadrature = get_singular_quadrature(cell, singular_index); FEValues fe_v_singular( @@ -860,7 +860,7 @@ namespace Step34 // singularity is located. template <> - const Quadrature<2> &BEMProblem<3>::get_singular_quadrature( + Quadrature<2> BEMProblem<3>::get_singular_quadrature( const DoFHandler<2, 3>::active_cell_iterator &, const unsigned int index) const { @@ -878,22 +878,17 @@ namespace Step34 template <> - const Quadrature<1> &BEMProblem<2>::get_singular_quadrature( + Quadrature<1> BEMProblem<2>::get_singular_quadrature( const DoFHandler<1, 2>::active_cell_iterator &cell, const unsigned int index) const { Assert(index < fe.n_dofs_per_cell(), ExcIndexRange(0, fe.n_dofs_per_cell(), index)); - static Quadrature<1> *q_pointer = nullptr; - if (q_pointer) - delete q_pointer; - - q_pointer = new QGaussLogR<1>(singular_quadrature_order, - fe.get_unit_support_points()[index], - 1. / cell->measure(), - true); - return (*q_pointer); + return QGaussLogR<1>(singular_quadrature_order, + fe.get_unit_support_points()[index], + 1. / cell->measure(), + true); } -- 2.39.5