From f4acf53010ff0fc0f88f373b7d1fb96c2045ab19 Mon Sep 17 00:00:00 2001 From: Sharaf Zaman Date: Thu, 9 Jun 2022 11:40:48 +0000 Subject: [PATCH] Fix race: Object (m_item) is operated on before it is assigned. The race happens in: QObject *obj = component->create(ctx); m_item = qobject_cast(obj); Truncated crash: #0 0x00007ffff5546354 in QQmlContext::parentContext() const () at /usr/lib/libQt5Qml.so.5 #1 0x00007fff68362cf3 in DelegateRecycler::syncModelProperties() (this=0x55555d3a9210) at delegaterecycler.cpp:162 #2 0x00007fff68336367 in DelegateRecycler::qt_static_metacall() at moc_delegaterecycler.cpp:229 #3 0x00007fff683365bd in DelegateRecycler::qt_metacall() at moc_delegaterecycler.cpp:308 --- src/delegaterecycler.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/delegaterecycler.cpp b/src/delegaterecycler.cpp index 76cb56f6d..a03f0d75f 100644 --- a/src/delegaterecycler.cpp +++ b/src/delegaterecycler.cpp @@ -127,7 +127,7 @@ DelegateRecycler::~DelegateRecycler() void DelegateRecycler::syncIndex() { const QVariant newIndex = m_propertiesTracker->property("trackedIndex"); - if (!newIndex.isValid()) { + if (!m_item || !newIndex.isValid()) { return; } QQmlContext *ctx = QQmlEngine::contextForObject(m_item)->parentContext(); @@ -137,7 +137,7 @@ void DelegateRecycler::syncIndex() void DelegateRecycler::syncModel() { const QVariant newModel = m_propertiesTracker->property("trackedModel"); - if (!newModel.isValid()) { + if (!m_item || !newModel.isValid()) { return; } QQmlContext *ctx = QQmlEngine::contextForObject(m_item)->parentContext(); @@ -156,7 +156,7 @@ void DelegateRecycler::syncModel() void DelegateRecycler::syncModelProperties() { const QVariant model = m_propertiesTracker->property("trackedModel"); - if (!model.isValid()) { + if (!m_item || !model.isValid()) { return; } QQmlContext *ctx = QQmlEngine::contextForObject(m_item)->parentContext(); @@ -174,7 +174,7 @@ void DelegateRecycler::syncModelProperties() void DelegateRecycler::syncModelData() { const QVariant newModelData = m_propertiesTracker->property("trackedModelData"); - if (!newModelData.isValid()) { + if (!m_item || !newModelData.isValid()) { return; } QQmlContext *ctx = QQmlEngine::contextForObject(m_item)->parentContext();