From 55cdb83073fa1a9cc0244e271790ee7f8ce13c29 Mon Sep 17 00:00:00 2001 From: dhthwy <302825+dhthwy@users.noreply.github.com> Date: Wed, 26 Nov 2025 12:26:20 -0500 Subject: [PATCH 1/2] fix debug plugin use-after-free on shutdown --- library/include/DebugManager.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/library/include/DebugManager.h b/library/include/DebugManager.h index d910efd4ad..1834915e72 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 From eb8ba905ccfa7777883584f58d57883b52ec966a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 26 Nov 2025 17:42:21 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- library/include/DebugManager.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/include/DebugManager.h b/library/include/DebugManager.h index 1834915e72..94cce64202 100644 --- a/library/include/DebugManager.h +++ b/library/include/DebugManager.h @@ -96,9 +96,9 @@ class DFHACK_EXPORT DebugManager : public std::vector { //! Get the singleton object static DebugManager& getInstance() { - // 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. + // 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; }