Skip to content

Commit

Permalink
Avoid a segfault after explicitly destroying a custom plugin factory …
Browse files Browse the repository at this point in the history
…object
  • Loading branch information
klayoutmatthias committed Jan 12, 2023
1 parent d79dfec commit 33af2b8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/laybasic/laybasic/gsiDeclLayPlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ class PluginBase
gsi::Callback f_tracking_position;
};

static std::map <std::string, PluginFactoryBase *> s_factories;

class PluginFactoryBase
: public lay::PluginDeclaration
{
Expand All @@ -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;
}
Expand All @@ -319,7 +328,6 @@ class PluginFactoryBase
keep ();

// 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);
if (f != s_factories.end ()) {
delete f->second;
Expand Down

0 comments on commit 33af2b8

Please sign in to comment.