From: Arnaud Giersch Date: Tue, 8 Jun 2021 12:11:50 +0000 (+0200) Subject: Fix memleaks with MPI_*_get_info, when info is duplicated. X-Git-Tag: v3.28~126 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/0def08e689276880f2f012a9ed335ccef2c0103e?ds=sidebyside Fix memleaks with MPI_*_get_info, when info is duplicated. --- diff --git a/src/smpi/include/smpi_info.hpp b/src/smpi/include/smpi_info.hpp index d655edcfd0..252cd87587 100644 --- a/src/smpi/include/smpi_info.hpp +++ b/src/smpi/include/smpi_info.hpp @@ -21,7 +21,7 @@ class Info : public F2C{ public: explicit Info() {this->add_f();} - explicit Info(const Info* orig) : map_(orig->map_) {this->add_f();} + explicit Info(const Info* orig); void ref(); static void unref(MPI_Info info); void set(const char* key, const char* value) { map_[key] = value; } diff --git a/src/smpi/mpi/smpi_comm.cpp b/src/smpi/mpi/smpi_comm.cpp index 452439f24b..017d010a79 100644 --- a/src/smpi/mpi/smpi_comm.cpp +++ b/src/smpi/mpi/smpi_comm.cpp @@ -564,9 +564,6 @@ void Comm::finish_rma_calls() const MPI_Info Comm::info() { - if (info_ == MPI_INFO_NULL) - info_ = new Info(); - info_->ref(); return info_; } diff --git a/src/smpi/mpi/smpi_file.cpp b/src/smpi/mpi/smpi_file.cpp index 9dc8f69cfc..4ad8f8f3b9 100644 --- a/src/smpi/mpi/smpi_file.cpp +++ b/src/smpi/mpi/smpi_file.cpp @@ -301,9 +301,6 @@ namespace smpi{ MPI_Info File::info() { - if (info_ == MPI_INFO_NULL) - info_ = new Info(); - info_->ref(); return info_; } diff --git a/src/smpi/mpi/smpi_info.cpp b/src/smpi/mpi/smpi_info.cpp index 33be51967c..f979b751d0 100644 --- a/src/smpi/mpi/smpi_info.cpp +++ b/src/smpi/mpi/smpi_info.cpp @@ -10,6 +10,13 @@ namespace simgrid { namespace smpi { +Info::Info(const Info* orig) +{ + if (orig != nullptr) + map_ = orig->map_; + this->add_f(); +} + void Info::ref() { refcount_++; diff --git a/src/smpi/mpi/smpi_win.cpp b/src/smpi/mpi/smpi_win.cpp index 216a200d1c..38f901aab6 100644 --- a/src/smpi/mpi/smpi_win.cpp +++ b/src/smpi/mpi/smpi_win.cpp @@ -130,9 +130,6 @@ void Win::get_group(MPI_Group* group){ MPI_Info Win::info() { - if (info_ == MPI_INFO_NULL) - info_ = new Info(); - info_->ref(); return info_; }