Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Plug memleaks with Fortran bindings.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sun, 23 May 2021 20:40:39 +0000 (22:40 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 25 May 2021 14:59:28 +0000 (16:59 +0200)
src/smpi/bindings/smpi_f77.cpp
src/smpi/bindings/smpi_f77_comm.cpp
src/smpi/bindings/smpi_f77_type.cpp
src/smpi/include/smpi_keyvals.hpp
src/smpi/mpi/smpi_keyvals.cpp

index bfdbbc5..85885bb 100644 (file)
@@ -287,7 +287,7 @@ void mpi_win_create_keyval_(void* copy_fn, void* delete_fn, int* keyval, void* e
 {
   smpi_copy_fn _copy_fn={nullptr,nullptr,nullptr,nullptr,nullptr,(*(int*)copy_fn) == 0 ? nullptr : reinterpret_cast<MPI_Win_copy_attr_function_fort*>(copy_fn)};
   smpi_delete_fn _delete_fn={nullptr,nullptr,nullptr,nullptr,nullptr,(*(int*)delete_fn) == 0 ? nullptr : reinterpret_cast<MPI_Win_delete_attr_function_fort*>(delete_fn)};
-  *ierr = simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Win>(_copy_fn, _delete_fn, keyval, extra_state);
+  *ierr = simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Win>(_copy_fn, _delete_fn, keyval, extra_state, true);
 }
 
 void mpi_win_free_keyval_(int* keyval, int* ierr)
@@ -809,7 +809,7 @@ void mpi_attr_put_ (int* comm, int* keyval, int* attr_value, int* ierr) {
 void mpi_keyval_create_ (void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr) {
   smpi_copy_fn _copy_fn={nullptr,nullptr,nullptr,(*(int*)copy_fn) == 0 ? nullptr : reinterpret_cast<MPI_Copy_function_fort*>(copy_fn),nullptr,nullptr};
   smpi_delete_fn _delete_fn={nullptr,nullptr,nullptr,(*(int*)delete_fn) == 0 ? nullptr : reinterpret_cast<MPI_Delete_function_fort*>(delete_fn),nullptr,nullptr};
-  *ierr = simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Comm>(_copy_fn, _delete_fn, keyval, extra_state);
+  *ierr = simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Comm>(_copy_fn, _delete_fn, keyval, extra_state, true);
 }
 
 void mpi_keyval_free_ (int* keyval, int* ierr) {
index 0113de4..91c80bb 100644 (file)
@@ -91,7 +91,7 @@ void mpi_comm_delete_attr_ (int* comm, int* comm_keyval, int* ierr){
 void mpi_comm_create_keyval_ (void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr){
   smpi_copy_fn _copy_fn={nullptr,nullptr,nullptr,(*(int*)copy_fn) == 0 ? nullptr : reinterpret_cast<MPI_Comm_copy_attr_function_fort*>(copy_fn),nullptr,nullptr};
   smpi_delete_fn _delete_fn={nullptr,nullptr,nullptr,(*(int*)delete_fn) == 0 ? nullptr : reinterpret_cast<MPI_Comm_delete_attr_function_fort*>(delete_fn),nullptr,nullptr};
-  *ierr = simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Comm>(_copy_fn, _delete_fn, keyval, extra_state);
+  *ierr = simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Comm>(_copy_fn, _delete_fn, keyval, extra_state, true);
 }
 
 void mpi_comm_free_keyval_ (int* keyval, int* ierr) {
index 1bd48b0..b136742 100644 (file)
@@ -76,7 +76,8 @@ void mpi_type_delete_attr_ (int* type, int* type_keyval, int* ierr){
 void mpi_type_create_keyval_ (void* copy_fn, void*  delete_fn, int* keyval, void* extra_state, int* ierr){
   smpi_copy_fn _copy_fn={nullptr,nullptr,nullptr,nullptr,(*(int*)copy_fn) == 0 ? nullptr : reinterpret_cast<MPI_Type_copy_attr_function_fort*>(copy_fn),nullptr};
   smpi_delete_fn _delete_fn={nullptr,nullptr,nullptr,nullptr,(*(int*)delete_fn) == 0 ? nullptr : reinterpret_cast<MPI_Type_delete_attr_function_fort*>(delete_fn),nullptr};
-  *ierr = simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Datatype>(_copy_fn, _delete_fn, keyval, extra_state);
+  *ierr =
+      simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Datatype>(_copy_fn, _delete_fn, keyval, extra_state, true);
 }
 
 void mpi_type_free_keyval_ (int* keyval, int* ierr) {
index aba0a51..77807a3 100644 (file)
@@ -35,6 +35,7 @@ struct smpi_key_elem {
   void* extra_state;
   int refcount;
   bool deleted;
+  bool delete_attr; // if true, xbt_free(attr) on delete: used by Fortran bindings
 };
 
 namespace simgrid{
@@ -52,7 +53,7 @@ class Keyval{
 //    static int keyval_id_;
     template <typename T>
     static int keyval_create(const smpi_copy_fn& copy_fn, const smpi_delete_fn& delete_fn, int* keyval,
-                             void* extra_state);
+                             void* extra_state, bool delete_attr = false);
     template <typename T> static int keyval_free(int* keyval);
     template <typename T> int attr_delete(int keyval);
     template <typename T> int attr_get(int keyval, void* attr_value, int* flag);
@@ -63,7 +64,8 @@ class Keyval{
 };
 
 template <typename T>
-int Keyval::keyval_create(const smpi_copy_fn& copy_fn, const smpi_delete_fn& delete_fn, int* keyval, void* extra_state)
+int Keyval::keyval_create(const smpi_copy_fn& copy_fn, const smpi_delete_fn& delete_fn, int* keyval, void* extra_state,
+                          bool delete_attr)
 {
   smpi_key_elem value;
   value.copy_fn     = copy_fn;
@@ -71,6 +73,7 @@ int Keyval::keyval_create(const smpi_copy_fn& copy_fn, const smpi_delete_fn& del
   value.extra_state = extra_state;
   value.refcount    = 0;
   value.deleted     = false;
+  value.delete_attr = delete_attr;
 
   *keyval = T::keyval_id_;
   T::keyvals_.emplace(*keyval, std::move(value));
index 8561a09..98bcb91 100644 (file)
@@ -4,8 +4,8 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-//#include "private.hpp"
 #include "smpi_keyvals.hpp"
+#include "xbt/sysdep.h"
 
 namespace simgrid{
 namespace smpi{
@@ -17,6 +17,8 @@ template <> int Keyval::call_deleter<Comm>(Comm* obj, const smpi_key_elem& elem,
     ret = elem.delete_fn.comm_delete_fn(obj, keyval, value, elem.extra_state);
   else if (elem.delete_fn.comm_delete_fn_fort != MPI_NULL_DELETE_FN)
     elem.delete_fn.comm_delete_fn_fort(obj, keyval, value, elem.extra_state, &ret);
+  if (elem.delete_attr)
+    xbt_free(value);
   return ret;
 }
 
@@ -27,6 +29,8 @@ template <> int Keyval::call_deleter<Win>(Win* obj, const smpi_key_elem& elem, i
     ret = elem.delete_fn.win_delete_fn(obj, keyval, value, elem.extra_state);
   else if (elem.delete_fn.win_delete_fn_fort != MPI_NULL_DELETE_FN)
     elem.delete_fn.win_delete_fn_fort(obj, keyval, value, elem.extra_state, &ret);
+  if (elem.delete_attr)
+    xbt_free(value);
   return ret;
 }
 
@@ -38,6 +42,8 @@ int Keyval::call_deleter<Datatype>(Datatype* obj, const smpi_key_elem& elem, int
     ret = elem.delete_fn.type_delete_fn(obj, keyval, value, elem.extra_state);
   else if (elem.delete_fn.type_delete_fn_fort != MPI_NULL_DELETE_FN)
     elem.delete_fn.type_delete_fn_fort(obj, keyval, value, elem.extra_state, &ret);
+  if (elem.delete_attr)
+    xbt_free(value);
   return ret;
 }