From 0b3265e38ff10e05e52480954a9ceb27d2a1bf0e Mon Sep 17 00:00:00 2001 From: Augustin Degomme Date: Tue, 2 Mar 2021 15:58:38 +0100 Subject: [PATCH] add leak checking for info and errhandlers --- src/smpi/bindings/smpi_pmpi_comm.cpp | 1 + src/smpi/include/smpi_info.hpp | 4 ++-- src/smpi/mpi/smpi_errhandler.cpp | 4 ++++ src/smpi/mpi/smpi_info.cpp | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/smpi/bindings/smpi_pmpi_comm.cpp b/src/smpi/bindings/smpi_pmpi_comm.cpp index 28aee048d8..005799957e 100644 --- a/src/smpi/bindings/smpi_pmpi_comm.cpp +++ b/src/smpi/bindings/smpi_pmpi_comm.cpp @@ -275,6 +275,7 @@ int PMPI_Errhandler_free(MPI_Errhandler* errhandler){ int PMPI_Errhandler_create(MPI_Handler_function* function, MPI_Errhandler* errhandler){ CHECK_NULL(2, MPI_ERR_ARG, errhandler) *errhandler=new simgrid::smpi::Errhandler(function); + (*errhandler)->add_f(); return MPI_SUCCESS; } diff --git a/src/smpi/include/smpi_info.hpp b/src/smpi/include/smpi_info.hpp index ef7c3743bd..91aeaee354 100644 --- a/src/smpi/include/smpi_info.hpp +++ b/src/smpi/include/smpi_info.hpp @@ -20,8 +20,8 @@ class Info : public F2C{ int refcount_ = 1; public: - Info() = default; - explicit Info(const Info* orig) : map_(orig->map_) {} + explicit Info() {this->add_f();} + explicit Info(const Info* orig) : map_(orig->map_) {this->add_f();} ~Info() override = default; void ref(); static void unref(MPI_Info info); diff --git a/src/smpi/mpi/smpi_errhandler.cpp b/src/smpi/mpi/smpi_errhandler.cpp index 6ed4b5148a..9e237d4257 100644 --- a/src/smpi/mpi/smpi_errhandler.cpp +++ b/src/smpi/mpi/smpi_errhandler.cpp @@ -45,11 +45,15 @@ void Errhandler::ref() } void Errhandler::unref(Errhandler* errhandler){ + if(errhandler == MPI_ERRORS_ARE_FATAL || errhandler == MPI_ERRORS_RETURN) + return; errhandler->refcount_--; if(errhandler->refcount_==0){ + F2C::free_f(errhandler->c2f()); delete errhandler; } } } + } diff --git a/src/smpi/mpi/smpi_info.cpp b/src/smpi/mpi/smpi_info.cpp index bd68f4c23c..ed832a6e27 100644 --- a/src/smpi/mpi/smpi_info.cpp +++ b/src/smpi/mpi/smpi_info.cpp @@ -17,6 +17,7 @@ void Info::ref() void Info::unref(Info* info){ info->refcount_--; if(info->refcount_==0){ + F2C::free_f(info->c2f()); delete info; } } -- 2.20.1