From cfac27251af5df4352f747c4539ea9f65450f05a Mon Sep 17 00:00:00 2001 From: Dave Walker Date: Sun, 5 Oct 2025 15:24:49 +0100 Subject: [PATCH] debug: fix data race in Debug::log() (#11931) * debug: fix data race in Debug::log() The templated Debug::log() had mutex protection but the non-template overload it calls didn't, causing crashes when plugins called log from background threads (like hypr-dynamic-cursors loading cursor themes). Fixed by moving the mutex lock from the template version into the non-template version, so all writes to shared state are protected. Fixes: hyprwm/Hyprland#11929 Fixes: VirtCode/hypr-dynamic-cursors#99 * debug: apply clang-format to Log.cpp Fix formatting to satisfy CI clang-format check. --------- Co-authored-by: Dave Walker --- src/debug/Log.cpp | 4 +++- src/debug/Log.hpp | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/debug/Log.cpp b/src/debug/Log.cpp index b5865f0a..8d84840e 100644 --- a/src/debug/Log.cpp +++ b/src/debug/Log.cpp @@ -24,7 +24,9 @@ void Debug::log(eLogLevel level, std::string str) { if (m_shuttingDown) return; - std::string coloredStr = str; + std::lock_guard guard(m_logMutex); + + std::string coloredStr = str; //NOLINTBEGIN switch (level) { case LOG: diff --git a/src/debug/Log.hpp b/src/debug/Log.hpp index 6a380783..c3146805 100644 --- a/src/debug/Log.hpp +++ b/src/debug/Log.hpp @@ -42,8 +42,6 @@ namespace Debug { template //NOLINTNEXTLINE void log(eLogLevel level, std::format_string fmt, Args&&... args) { - std::lock_guard guard(m_logMutex); - if (level == TRACE && !m_trace) return;