diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-09-22 09:05:57 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-09-23 10:30:57 +0200 |
commit | 643dfc7cc4fc487abf2dde4ff4343a16edad1db2 (patch) | |
tree | 34852c91674f29d899776214ce02fdaa3767f5b7 | |
parent | 1843f3f1bd3626d331ddd04506b64bb34982eb82 (diff) |
QThread: Work around potential crash during objectName access
We access objectName from a different thread than the thread which owns
it. This is inherently racy, but was apparently not an issue in practice
before. With the new binding system, we however seem to encounter a case
where we do run into issues. This patch migitates it by bypassing the
binding system (using valueBypassingBindings).
Task-number: QTBUG-96718
Pick-to: 6.2 dev
Change-Id: I9d8f2354ae282893a32c8a23381d0056ceef7c40
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r-- | src/corelib/thread/qthread_unix.cpp | 10 | ||||
-rw-r--r-- | src/corelib/thread/qthread_win.cpp | 7 |
2 files changed, 14 insertions, 3 deletions
diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index 8d2c83d519..205ae50035 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -315,10 +315,16 @@ void *QThreadPrivate::start(void *arg) // Sets the name of the current thread. We can only do this // when the thread is starting, as we don't have a cross // platform way of setting the name of an arbitrary thread. - if (Q_LIKELY(thr->objectName().isEmpty())) + + // avoid interacting with the binding system while thread is + // not properly running yet + auto priv = QObjectPrivate::get(thr); + QString objectName = priv->extraData ? priv->extraData->objectName.valueBypassingBindings() + : QString(); + if (Q_LIKELY(objectName.isEmpty())) setCurrentThreadName(thr->metaObject()->className()); else - setCurrentThreadName(thr->objectName().toLocal8Bit()); + setCurrentThreadName(objectName.toLocal8Bit()); } #endif diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp index 820ffa1149..8aa3f4c58b 100644 --- a/src/corelib/thread/qthread_win.cpp +++ b/src/corelib/thread/qthread_win.cpp @@ -316,7 +316,12 @@ unsigned int __stdcall QT_ENSURE_STACK_ALIGNED_FOR_SSE QThreadPrivate::start(voi #if !defined(QT_NO_DEBUG) && defined(Q_CC_MSVC) // sets the name of the current thread. - QByteArray objectName = thr->objectName().toLocal8Bit(); + + // avoid interacting with the binding system while thread is + // not properly running yet + auto priv = QObjectPrivate::get(thr); + QByteArray objectName = (priv->extraData ? priv->extraData->objectName.valueBypassingBindings() + : QString()).toLocal8Bit(); qt_set_thread_name(HANDLE(-1), objectName.isEmpty() ? thr->metaObject()->className() : objectName.constData()); |