From 5f92ea0b63d6abf93306250c676da32c98081d8e Mon Sep 17 00:00:00 2001 From: degomme Date: Tue, 16 Aug 2016 02:09:04 +0200 Subject: [PATCH] better handling of info_* in smpi to avoid leaks --- src/smpi/smpi_f77.cpp | 7 +------ src/smpi/smpi_pmpi.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/smpi/smpi_f77.cpp b/src/smpi/smpi_f77.cpp index 0ab3b36d02..2a955b57c6 100644 --- a/src/smpi/smpi_f77.cpp +++ b/src/smpi/smpi_f77.cpp @@ -782,6 +782,7 @@ void mpi_info_set_( int *info, char *key, char *value, int* ierr, unsigned int k *ierr = MPI_Info_set( smpi_info_f2c(*info), tkey, tvalue); xbt_free(tkey); + xbt_free(tvalue); } void mpi_info_get_ (int* info,char *key,int* valuelen, char *value, int *flag, int* ierr, unsigned int keylen ){ @@ -810,12 +811,6 @@ void mpi_info_get_ (int* info,char *key,int* valuelen, char *value, int *flag, i void mpi_info_free_(int* info, int* ierr){ MPI_Info tmp = smpi_info_f2c(*info); - const char* key; - char* val; - xbt_dict_cursor_t cursor; - xbt_dict_foreach(tmp->info_dict,cursor,key,val) { - xbt_free(val); - } *ierr = MPI_Info_free(&tmp); if(*ierr == MPI_SUCCESS) { free_info(*info); diff --git a/src/smpi/smpi_pmpi.cpp b/src/smpi/smpi_pmpi.cpp index 1f4add0efb..1315a65ed6 100644 --- a/src/smpi/smpi_pmpi.cpp +++ b/src/smpi/smpi_pmpi.cpp @@ -3120,7 +3120,7 @@ int PMPI_Info_create( MPI_Info *info){ if (info == nullptr) return MPI_ERR_ARG; *info = xbt_new(s_smpi_mpi_info_t, 1); - (*info)->info_dict= xbt_dict_new_homogeneous(nullptr); + (*info)->info_dict= xbt_dict_new_homogeneous(xbt_free_f); (*info)->refcount=1; return MPI_SUCCESS; } @@ -3129,7 +3129,7 @@ int PMPI_Info_set( MPI_Info info, char *key, char *value){ if (info == nullptr || key == nullptr || value == nullptr) return MPI_ERR_ARG; - xbt_dict_set(info->info_dict, key, (void*)value, nullptr); + xbt_dict_set(info->info_dict, key, xbt_strdup(value), nullptr); return MPI_SUCCESS; } @@ -3164,13 +3164,13 @@ int PMPI_Info_dup(MPI_Info info, MPI_Info *newinfo){ if (info == nullptr || newinfo==nullptr) return MPI_ERR_ARG; *newinfo = xbt_new(s_smpi_mpi_info_t, 1); - (*newinfo)->info_dict= xbt_dict_new_homogeneous(nullptr); + (*newinfo)->info_dict= xbt_dict_new_homogeneous(xbt_free_f); (*newinfo)->refcount=1; xbt_dict_cursor_t cursor = nullptr; int *key; void* data; xbt_dict_foreach(info->info_dict,cursor,key,data){ - xbt_dict_set((*newinfo)->info_dict, reinterpret_cast(key), data, nullptr); + xbt_dict_set((*newinfo)->info_dict, reinterpret_cast(key), xbt_strdup(reinterpret_cast(data)), nullptr); } return MPI_SUCCESS; } -- 2.20.1