Salome HOME
Correction of bug concerning UNIV info status.
[tools/medcoupling.git] / src / ParaMEDMEM / MPIProcessorGroup.cxx
index 2a492e73bceda9721ebc825f9e42a85bd4e78d7f..055cc5122c8608a2244eafcd13a6ca632fff28e9 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2015  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -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?
   }
   /*!
     @}