Skip to content

Commit

Permalink
Assert if CoUninitialize is called on wrong thread
Browse files Browse the repository at this point in the history
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ø <[email protected]>
  • Loading branch information
jogerh committed Feb 21, 2024
1 parent 974d791 commit 751ca5e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/corelib/kernel/qfunctions_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ QComHelper::QComHelper(COINIT concurrencyModel)

QComHelper::~QComHelper()
{
Q_ASSERT(m_threadId == GetCurrentThreadId());
if (SUCCEEDED(m_initResult))
CoUninitialize();
}
Expand Down
1 change: 1 addition & 0 deletions src/corelib/kernel/qfunctions_win_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Q_CORE_EXPORT QComHelper

private:
HRESULT m_initResult = E_FAIL;
DWORD m_threadId{ GetCurrentThreadId() };
};

Q_CORE_EXPORT bool qt_win_hasPackageIdentity();
Expand Down

0 comments on commit 751ca5e

Please sign in to comment.