From 751ca5e5bdb5918834af7c43d09f457a805d80f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8ger=20Hanseg=C3=A5rd?= Date: Sat, 27 Jan 2024 19:58:48 +0100 Subject: [PATCH] Assert if CoUninitialize is called on wrong thread MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every call to CoInitialize on a thread must be paired up with a call to CoUninitialized on that same thread. QComHelper helps ensuring this, but if an object using QComHelper is not created and destroyed on the same thread, we end up in loosing this pairing. This patch helps detecting such issues. Task-number: QTBUG-121495 Change-Id: I07984437d1515d7ef61820d7152c339924b36e4b Reviewed-by: Tor Arne Vestbø --- src/corelib/kernel/qfunctions_win.cpp | 1 + src/corelib/kernel/qfunctions_win_p.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/corelib/kernel/qfunctions_win.cpp b/src/corelib/kernel/qfunctions_win.cpp index d5ce3e5894..048fdbc934 100644 --- a/src/corelib/kernel/qfunctions_win.cpp +++ b/src/corelib/kernel/qfunctions_win.cpp @@ -28,6 +28,7 @@ QComHelper::QComHelper(COINIT concurrencyModel) QComHelper::~QComHelper() { + Q_ASSERT(m_threadId == GetCurrentThreadId()); if (SUCCEEDED(m_initResult)) CoUninitialize(); } diff --git a/src/corelib/kernel/qfunctions_win_p.h b/src/corelib/kernel/qfunctions_win_p.h index 540405bd2f..ab5417f8a2 100644 --- a/src/corelib/kernel/qfunctions_win_p.h +++ b/src/corelib/kernel/qfunctions_win_p.h @@ -39,6 +39,7 @@ public: private: HRESULT m_initResult = E_FAIL; + DWORD m_threadId{ GetCurrentThreadId() }; }; Q_CORE_EXPORT bool qt_win_hasPackageIdentity();