Skip to content

Commit

Permalink
Create PluginManager instance as function-local static
Browse files Browse the repository at this point in the history
Global statics gets destroyed last during the exit sequence, at that time static local wxConvFileName is already destroyed.

PluginManager flushes config file to disk during destruction, which result in accessing deleted object.
By making PluginManager function-local static we ensure that it will be deleted prior to wxConvFileName
  • Loading branch information
kryksyh committed Oct 19, 2024
1 parent 1b6cc65 commit 503984d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
11 changes: 2 additions & 9 deletions libraries/lib-module-manager/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,6 @@ bool PluginManager::RemoveConfig(ConfigurationType type, const PluginID & ID,
//
// ============================================================================

// The one and only PluginManager
std::unique_ptr<PluginManager> PluginManager::mInstance{};

// ----------------------------------------------------------------------------
// Creation/Destruction
// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -379,12 +376,8 @@ static PluginManager::ConfigFactory sFactory;

PluginManager & PluginManager::Get()
{
if (!mInstance)
{
mInstance.reset(safenew PluginManager);
}

return *mInstance;
static PluginManager instance;
return instance;
}

void PluginManager::Initialize(ConfigFactory factory)
Expand Down
2 changes: 0 additions & 2 deletions libraries/lib-module-manager/PluginManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,6 @@ class MODULE_MANAGER_API PluginManager final
wxString ConvertID(const PluginID & ID);

private:
friend std::default_delete<PluginManager>;
static std::unique_ptr<PluginManager> mInstance;

bool IsDirty();
void SetDirty(bool dirty = true);
Expand Down

0 comments on commit 503984d

Please sign in to comment.