Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into 'master'
authorAugustin Degomme <adegomme@gmail.com>
Sun, 17 Jan 2021 16:07:31 +0000 (17:07 +0100)
committerAugustin Degomme <adegomme@gmail.com>
Sun, 17 Jan 2021 16:07:31 +0000 (17:07 +0100)
Fix a few potential memory leaks in SMPI colls

See merge request simgrid/simgrid!46

src/smpi/colls/allgather/allgather-NTSLR-NB.cpp
src/smpi/colls/reduce_scatter/reduce_scatter-mpich.cpp

index ae9d195..1745ced 100644 (file)
@@ -25,8 +25,6 @@ allgather__NTSLR_NB(const void *sbuf, int scount, MPI_Datatype stype,
   size = comm->size();
   rextent = rtype->get_extent();
   sextent = stype->get_extent();
-  auto* rrequest_array = new MPI_Request[size];
-  auto* srequest_array = new MPI_Request[size];
 
   // irregular case use default MPI functions
   if (scount * sextent != rcount * rextent) {
@@ -49,6 +47,9 @@ allgather__NTSLR_NB(const void *sbuf, int scount, MPI_Datatype stype,
   //start sending logical ring message
   int increment = scount * sextent;
 
+  auto* rrequest_array = new MPI_Request[size];
+  auto* srequest_array = new MPI_Request[size];
+
   //post all irecv first
   for (i = 0; i < size - 1; i++) {
     recv_offset = ((rank - i - 1 + size) % size) * increment;
index c8a101b..46f59c6 100644 (file)
@@ -108,8 +108,11 @@ int reduce_scatter__mpich_pair(const void *sendbuf, void *recvbuf, const int rec
                   /* copy result back into recvbuf */
                   mpi_errno =
                       Datatype::copy(tmp_recvbuf, recvcounts[rank], datatype, recvbuf, recvcounts[rank], datatype);
-                  if (mpi_errno)
+                  if (mpi_errno) {
+                   delete[] disps;
+                    smpi_free_tmp_buffer(tmp_recvbuf);
                     return (mpi_errno);
+                 }
                 }
                 else {
                   if (op != MPI_OP_NULL)
@@ -117,8 +120,11 @@ int reduce_scatter__mpich_pair(const void *sendbuf, void *recvbuf, const int rec
                   /* copy result back into recvbuf */
                   mpi_errno = Datatype::copy(tmp_recvbuf, recvcounts[rank], datatype,
                                              ((char*)recvbuf + disps[rank] * extent), recvcounts[rank], datatype);
-                  if (mpi_errno)
+                  if (mpi_errno) {
+                   delete[] disps;
+                    smpi_free_tmp_buffer(tmp_recvbuf);
                     return (mpi_errno);
+                 }
                 }
             }
         }
@@ -131,7 +137,11 @@ int reduce_scatter__mpich_pair(const void *sendbuf, void *recvbuf, const int rec
                                        recvcounts[rank], datatype,
                                        recvbuf,
                                        recvcounts[rank], datatype );
-            if (mpi_errno) return(mpi_errno);
+            if (mpi_errno) {
+             delete[] disps;
+              smpi_free_tmp_buffer(tmp_recvbuf);
+             return (mpi_errno);
+           }
         }
 
         delete[] disps;
@@ -307,8 +317,10 @@ int reduce_scatter__mpich_rdb(const void *sendbuf, void *recvbuf, const int recv
     else
       mpi_errno = Datatype::copy(recvbuf, total_count, datatype, tmp_results, total_count, datatype);
 
-    if (mpi_errno)
+    if (mpi_errno) {
+      delete[] disps;
       return (mpi_errno);
+    }
 
     mask = 0x1;
     i    = 0;