Avoid a segfault after explicitly destroying a custom plugin factory object

This commit is contained in:
Matthias Koefferlein 2023-01-12 21:03:24 +01:00
parent d79dfec255
commit 33af2b8fcc
1 changed files with 9 additions and 1 deletions

View File

@ -291,6 +291,8 @@ public:
gsi::Callback f_tracking_position; gsi::Callback f_tracking_position;
}; };
static std::map <std::string, PluginFactoryBase *> s_factories;
class PluginFactoryBase class PluginFactoryBase
: public lay::PluginDeclaration : public lay::PluginDeclaration
{ {
@ -304,6 +306,13 @@ public:
~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; delete mp_registration;
mp_registration = 0; mp_registration = 0;
} }
@ -319,7 +328,6 @@ public:
keep (); keep ();
// remove an existing factory with the same name // remove an existing factory with the same name
static std::map <std::string, PluginFactoryBase *> s_factories;
std::map <std::string, PluginFactoryBase *>::iterator f = s_factories.find (name); std::map <std::string, PluginFactoryBase *>::iterator f = s_factories.find (name);
if (f != s_factories.end ()) { if (f != s_factories.end ()) {
delete f->second; delete f->second;