From e5e064b170bf694a24e0225f5cafea5829c9ad72 Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Thu, 9 Sep 2021 17:01:14 +0200 Subject: Fix binding guard in property evaluation The comment for keepAlive means that it should be destroyed after the updateGuard goes out of scope and restores its value. In this case keepAlive should be actually created *before* updateGuard, not after it. Task-number: QTBUG-96303 Change-Id: I4f8e67b49c1d6579228e22111105fb936f1f94db Reviewed-by: Fabian Kosmale (cherry picked from commit 248f0aad1c4f1c6e7e03ad265c2011390dca75ef) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/kernel/qproperty_p.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/corelib/kernel/qproperty_p.h b/src/corelib/kernel/qproperty_p.h index 55f0dc032c..6fcef939f7 100644 --- a/src/corelib/kernel/qproperty_p.h +++ b/src/corelib/kernel/qproperty_p.h @@ -707,18 +707,18 @@ inline void QPropertyBindingPrivate::evaluateRecursive_inline(QBindingStatus *st return; } - QScopedValueRollback updateGuard(updating, true); - /* - * Evaluating the binding might lead to the binding being broken. This can - * cause ref to reach zero at the end of the function. However, the - * updateGuard's destructor will then still trigger, trying to set the - * updating bool to its old value - * To prevent this, we create a QPropertyBindingPrivatePtr which ensures - * that the object is still alive when updateGuard's dtor runs. - */ + * Evaluating the binding might lead to the binding being broken. This can + * cause ref to reach zero at the end of the function. However, the + * updateGuard's destructor will then still trigger, trying to set the + * updating bool to its old value + * To prevent this, we create a QPropertyBindingPrivatePtr which ensures + * that the object is still alive when updateGuard's dtor runs. + */ QPropertyBindingPrivatePtr keepAlive {this}; + QScopedValueRollback updateGuard(updating, true); + QtPrivate::BindingEvaluationState evaluationFrame(this, status); auto bindingFunctor = reinterpret_cast(this) + -- cgit v1.2.1