From 33af2b8fcc7c734330f82ace8a399ec464dc797c Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Thu, 12 Jan 2023 21:03:24 +0100 Subject: [PATCH] Avoid a segfault after explicitly destroying a custom plugin factory object --- src/laybasic/laybasic/gsiDeclLayPlugin.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/laybasic/laybasic/gsiDeclLayPlugin.cc b/src/laybasic/laybasic/gsiDeclLayPlugin.cc index 609feca01d..7b9d449e2e 100644 --- a/src/laybasic/laybasic/gsiDeclLayPlugin.cc +++ b/src/laybasic/laybasic/gsiDeclLayPlugin.cc @@ -291,6 +291,8 @@ class PluginBase gsi::Callback f_tracking_position; }; +static std::map s_factories; + class PluginFactoryBase : public lay::PluginDeclaration { @@ -304,6 +306,13 @@ class PluginFactoryBase ~PluginFactoryBase () { + for (auto f = s_factories.begin (); f != s_factories.end (); ++f) { + if (f->second == this) { + s_factories.erase (f); + break; + } + } + delete mp_registration; mp_registration = 0; } @@ -319,7 +328,6 @@ class PluginFactoryBase keep (); // remove an existing factory with the same name - static std::map s_factories; std::map ::iterator f = s_factories.find (name); if (f != s_factories.end ()) { delete f->second;