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 <dave@daviey.com>
This commit is contained in:
Dave Walker 2025-10-05 15:24:49 +01:00 committed by GitHub
parent 76d998743a
commit cfac27251a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View file

@ -24,7 +24,9 @@ void Debug::log(eLogLevel level, std::string str) {
if (m_shuttingDown)
return;
std::string coloredStr = str;
std::lock_guard<std::mutex> guard(m_logMutex);
std::string coloredStr = str;
//NOLINTBEGIN
switch (level) {
case LOG:

View file

@ -42,8 +42,6 @@ namespace Debug {
template <typename... Args>
//NOLINTNEXTLINE
void log(eLogLevel level, std::format_string<Args...> fmt, Args&&... args) {
std::lock_guard<std::mutex> guard(m_logMutex);
if (level == TRACE && !m_trace)
return;