]> SALOME platform Git repositories - modules/med.git/commitdiff
Salome HOME
Memory leak fix on MPI_Group and when throwing in MPIProcessorGroup. abn/mpifix
authorabn <adrien.bruneton@cea.fr>
Wed, 22 Jul 2015 14:58:01 +0000 (16:58 +0200)
committerabn <adrien.bruneton@cea.fr>
Wed, 22 Jul 2015 14:58:01 +0000 (16:58 +0200)
src/ParaMEDMEM/MPIProcessorGroup.cxx
src/ParaMEDMEMTest/ParaMEDMEMTest.hxx
src/ParaMEDMEMTest/ParaMEDMEMTest_MPIProcessorGroup.cxx

index 3aea0d233a78a2e25d6d67d05b9a99ea687824db..055cc5122c8608a2244eafcd13a6ca632fff28e9 100644 (file)
@@ -110,12 +110,19 @@ namespace ParaMEDMEM
     copy<set<int>::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<int> 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<int> 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 <pstart || pstart<0)
-      throw INTERP_KERNEL::Exception("invalid argument in MPIProcessorGroup constructor (comm,pfirst,plast)");
+      {
+        _comm_interface.groupFree(&group_world);
+        throw INTERP_KERNEL::Exception("invalid argument in MPIProcessorGroup constructor (comm,pfirst,plast)");
+      }
     int nprocs=pend-pstart+1;
     int* ranks=new int[nprocs];
     for (int i=pstart; i<=pend;i++)
@@ -149,7 +159,10 @@ namespace ParaMEDMEM
     _comm_interface.groupIncl(group_world, nprocs, ranks, &_group);
   
     _comm_interface.commCreate(_world_comm, _group, &_comm);
+
+    // clean-up
     delete[] ranks;
+    _comm_interface.groupFree(&group_world);  // MPI_Group is a C structured and won't get de-allocated automatically?
   }
   /*!
     @}
index cbbb05c0b62817294a4455a8f266b079a0a29dc1..a8bf2b474dfbd4128f2798764dc313f1f431f244 100644 (file)
@@ -64,7 +64,7 @@ class ParaMEDMEMTest : public CppUnit::TestFixture
 #ifdef MED_ENABLE_FVM
   //can be added again after FVM correction for 2D
   //  CPPUNIT_TEST(testNonCoincidentDEC_2D);
-  CPPUNIT_TEST(testNonCoincidentDEC_3D); 
+  CPPUNIT_TEST(testNonCoincidentDEC_3D);
 #endif
   CPPUNIT_TEST(testStructuredCoincidentDEC);
   CPPUNIT_TEST(testStructuredCoincidentDEC);
index 952a59983a4b74dfc3883f58093684e02bb56669..3c6fc3b257ce4d10866109aa845099ec14a6e64e 100644 (file)
@@ -58,18 +58,20 @@ using namespace ParaMEDMEM;
 void ParaMEDMEMTest::testMPIProcessorGroup_constructor()
 {
   CommInterface comm_interface;
-  MPIProcessorGroup* group= new MPIProcessorGroup(comm_interface);
+  MPIProcessorGroup* group;
   int size;
   MPI_Comm_size(MPI_COMM_WORLD, &size);
+
+  group= new MPIProcessorGroup(comm_interface);
   CPPUNIT_ASSERT_EQUAL(size,group->size());
   int size2;
   const MPI_Comm* communicator=group->getComm();
   MPI_Comm_size(*communicator, &size2);
   CPPUNIT_ASSERT_EQUAL(size,size2);
   delete group;
-  
+
   set <int> 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 plast<pfirst
   CPPUNIT_ASSERT_THROW(group=new MPIProcessorGroup(comm_interface,1,0),INTERP_KERNEL::Exception);
   //throws because plast is beyond size-1
@@ -92,7 +93,7 @@ void ParaMEDMEMTest::testMPIProcessorGroup_constructor()
       CPPUNIT_ASSERT_EQUAL(group->size(),size-1);
       delete group;
     }
-  
+
 }
  
 void ParaMEDMEMTest::testMPIProcessorGroup_boolean()