]> repos.lx-s.de Git - winmute.git/commitdiff
Fixed possible block on wndMutex in WMLog.
authorlx-s <lx-s@users.noreply.github.com>
Wed, 8 Jul 2026 08:43:11 +0000 (10:43 +0200)
committerlx-s <lx-s@users.noreply.github.com>
Wed, 8 Jul 2026 08:43:11 +0000 (10:43 +0200)
WinMute/WMLog.cpp

index 3cbbb5020523fb614f4c4bb3e0f101654e8e41ae..7f65dff1381c71135e68d89648027ed5c7a1e47c 100644 (file)
@@ -156,8 +156,15 @@ void WMLog::StoreMessage(LogLevel level, const wchar_t* msg)
    }
 
    {
-      const std::scoped_lock<std::mutex> lock(wndMutex_);
-      for (const auto hWnd : registeredWindows_) {
+      // Copy the window list first: holding wndMutex_ across SendMessageW
+      // deadlocks if the UI thread is simultaneously blocked on wndMutex_
+      // in (Un)RegisterForLogUpdates.
+      std::vector<HWND> logWindows;
+      {
+         const std::scoped_lock<std::mutex> lock(wndMutex_);
+         logWindows = registeredWindows_;
+      }
+      for (const auto hWnd : logWindows) {
          if (IsWindow(hWnd)) {
             SendMessageW(hWnd, WM_LOG_UPDATED, 0, reinterpret_cast<LPARAM>(&lm));
          }