diff --git a/library/include/DebugManager.h b/library/include/DebugManager.h index d910efd4ad..94cce64202 100644 --- a/library/include/DebugManager.h +++ b/library/include/DebugManager.h @@ -96,8 +96,11 @@ class DFHACK_EXPORT DebugManager : public std::vector { //! Get the singleton object static DebugManager& getInstance() { - static DebugManager instance; - return instance; + // Plugins may still hold pointers to DebugManager's instance during shutdown. + // If DebugManager's dtor runs first, use-after-free may ensue. + // Intentionally leak to avoid this issue. + static DebugManager* instance = new DebugManager(); + return *instance; } // don't bother to protect these with mutexes. we don't want to pay the