From 8b48ca4f34730edca83b640560e3ffbaac382082 Mon Sep 17 00:00:00 2001 From: Copilot <223556219+Copilot@users.noreply.github.com> Date: Sun, 31 May 2026 20:16:28 -0700 Subject: [PATCH] Hold m_loggersMutex in LoggerSystem::Shutdown Log already takes m_loggersMutex around the lookup/emplace into m_loggers, but Shutdown iterated and cleared the same map with no lock. Any plugin thread or in-flight hook callback that called Log during shutdown could race against the iteration or use-after-clear. The race window is small but not theoretical: in the reverse-order shutdown, LoggerSystem::Shutdown runs last while RED4ext's own detours are still attached (those are detached in App::Destruct, see issue #141). Take the scoped_lock at the top of Shutdown so the flush + clear pair is atomic with respect to Log. Fixes #139 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/dll/Systems/LoggerSystem.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dll/Systems/LoggerSystem.cpp b/src/dll/Systems/LoggerSystem.cpp index 132bbe45..dd00d94d 100644 --- a/src/dll/Systems/LoggerSystem.cpp +++ b/src/dll/Systems/LoggerSystem.cpp @@ -21,6 +21,8 @@ void LoggerSystem::Startup() void LoggerSystem::Shutdown() { + std::scoped_lock _(m_loggersMutex); + auto count = m_loggers.size(); spdlog::trace("Flusing {} logger(s)...", count);