From d2ea1c98e747e2e8ec9cba37e637e424286b9876 Mon Sep 17 00:00:00 2001 From: abn Date: Wed, 22 Jul 2015 16:58:01 +0200 Subject: [PATCH] Memory leak fix on MPI_Group and when throwing in MPIProcessorGroup. --- src/ParaMEDMEM/MPIProcessorGroup.cxx | 17 +++++++++++++++-- src/ParaMEDMEMTest/ParaMEDMEMTest.hxx | 2 +- .../ParaMEDMEMTest_MPIProcessorGroup.cxx | 13 +++++++------ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/ParaMEDMEM/MPIProcessorGroup.cxx b/src/ParaMEDMEM/MPIProcessorGroup.cxx index 3aea0d233..055cc5122 100644 --- a/src/ParaMEDMEM/MPIProcessorGroup.cxx +++ b/src/ParaMEDMEM/MPIProcessorGroup.cxx @@ -110,12 +110,19 @@ namespace ParaMEDMEM copy::const_iterator,int*> (_proc_ids.begin(), _proc_ids.end(), ranks); for (int i=0; i< (int)_proc_ids.size();i++) if (ranks[i]>size_world-1) - throw INTERP_KERNEL::Exception("invalid rank in set argument of MPIProcessorGroup constructor"); + { + delete[] ranks; + _comm_interface.groupFree(&group_world); // MPI_Group is a C structure and won't get de-allocated automatically? + throw INTERP_KERNEL::Exception("invalid rank in set argument of MPIProcessorGroup constructor"); + } _comm_interface.groupIncl(group_world, _proc_ids.size(), ranks, &_group); _comm_interface.commCreate(_world_comm, _group, &_comm); + + // clean-up delete[] ranks; + _comm_interface.groupFree(&group_world); // MPI_Group is a C structure and won't get de-allocated automatically? } /*! Creates a processor group that is based on the processors between \a pstart and \a pend. @@ -138,7 +145,10 @@ namespace ParaMEDMEM _comm_interface.commGroup(_world_comm, &group_world); if (pend>size_world-1 || pend size()); int size2; const MPI_Comm* communicator=group->getComm(); MPI_Comm_size(*communicator, &size2); CPPUNIT_ASSERT_EQUAL(size,size2); delete group; - + set procs; - + procs.insert(0); procs.insert(1); if (size==1) @@ -80,8 +82,7 @@ void ParaMEDMEMTest::testMPIProcessorGroup_constructor() CPPUNIT_ASSERT_EQUAL (group->size(),2); delete group; } - - + //throws because plastsize(),size-1); delete group; } - + } void ParaMEDMEMTest::testMPIProcessorGroup_boolean() -- 2.39.2