From: abn Date: Wed, 22 Jul 2015 14:58:01 +0000 (+0200) Subject: Memory leak fix on MPI_Group and when throwing in MPIProcessorGroup. X-Git-Tag: V7_7_0a1~5^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fabn%2Fmpifix;p=tools%2Fmedcoupling.git Memory leak fix on MPI_Group and when throwing in MPIProcessorGroup. --- 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()