From f32336ba61cacec6b0bbd33b90e532f6678748fc Mon Sep 17 00:00:00 2001 From: Augustin Degomme Date: Tue, 30 Apr 2019 14:26:38 +0200 Subject: [PATCH] cleanup dup_with_info to avoid leaking in some cases --- src/smpi/bindings/smpi_pmpi_comm.cpp | 4 +--- src/smpi/include/smpi_comm.hpp | 1 + src/smpi/mpi/smpi_comm.cpp | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/smpi/bindings/smpi_pmpi_comm.cpp b/src/smpi/bindings/smpi_pmpi_comm.cpp index dc4d87a779..7291ed2cae 100644 --- a/src/smpi/bindings/smpi_pmpi_comm.cpp +++ b/src/smpi/bindings/smpi_pmpi_comm.cpp @@ -113,9 +113,7 @@ int PMPI_Comm_dup_with_info(MPI_Comm comm, MPI_Info info, MPI_Comm * newcomm) } else if (newcomm == nullptr) { return MPI_ERR_ARG; } else { - comm->dup(newcomm); - if(info!=MPI_INFO_NULL) - (*newcomm)->set_info(info); + comm->dup_with_info(info, newcomm); return MPI_SUCCESS; } } diff --git a/src/smpi/include/smpi_comm.hpp b/src/smpi/include/smpi_comm.hpp index eab2d2ce1b..a71e1f588e 100644 --- a/src/smpi/include/smpi_comm.hpp +++ b/src/smpi/include/smpi_comm.hpp @@ -39,6 +39,7 @@ public: Comm() = default; Comm(MPI_Group group, MPI_Topology topo, int smp = 0); int dup(MPI_Comm* newcomm); + int dup_with_info(MPI_Info info, MPI_Comm* newcomm); MPI_Group group(); MPI_Topology topo() { return topo_; } int size(); diff --git a/src/smpi/mpi/smpi_comm.cpp b/src/smpi/mpi/smpi_comm.cpp index 7c13694d9e..adb7a99c44 100644 --- a/src/smpi/mpi/smpi_comm.cpp +++ b/src/smpi/mpi/smpi_comm.cpp @@ -90,6 +90,21 @@ int Comm::dup(MPI_Comm* newcomm){ } } } + //duplicate info if present + if(info_!=MPI_INFO_NULL) + (*newcomm)->info_ = new simgrid::smpi::Info(info_); + return ret; +} + +int Comm::dup_with_info(MPI_Info info, MPI_Comm* newcomm){ + int ret = dup(newcomm); + if((*newcomm)->info_!=MPI_INFO_NULL){ + simgrid::smpi::Info::unref((*newcomm)->info_); + (*newcomm)->info_=MPI_INFO_NULL; + } + if(info != MPI_INFO_NULL){ + (*newcomm)->info_=info; + } return ret; } -- 2.20.1