From ea061c14902cb8bca3d90e15a38982b1fcbd55f8 Mon Sep 17 00:00:00 2001
From: Joseph Mirabel <jmirabel@laas.fr>
Date: Wed, 26 Sep 2018 19:38:22 +0200
Subject: [PATCH] Calls destroySotExternalInterface on clean up

---
 src/sot_loader_basic.cpp | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/src/sot_loader_basic.cpp b/src/sot_loader_basic.cpp
index d2dd6f8..94e825c 100644
--- a/src/sot_loader_basic.cpp
+++ b/src/sot_loader_basic.cpp
@@ -214,6 +214,25 @@ void SotLoaderBasic::Initialization()
 void SotLoaderBasic::CleanUp()
 {
   dynamicgraph::PoolStorage::destroy();
+  // We do not destroy the FactoryStorage singleton because the module will not
+  // be reloaded at next initialization (because Python C API cannot safely
+  // unload a module...).
+  // SignalCaster singleton could probably be destroyed.
+
+  // Load the symbols.
+  destroySotExternalInterface_t * destroySot =
+    reinterpret_cast<destroySotExternalInterface_t *> 
+    (reinterpret_cast<long> 
+     (dlsym(sotRobotControllerLibrary_, 
+	    "destroySotExternalInterface")));
+  const char* dlsym_error = dlerror();
+  if (dlsym_error) {
+    std::cerr << "Cannot load symbol destroy: " << dlsym_error << '\n';
+    return ;
+  }
+
+  destroySot (sotController_);
+  sotController_ = NULL;
 
   /// Uncount the number of access to this library.
   dlclose(sotRobotControllerLibrary_);
-- 
GitLab