From c83b3b6e85a218022d94db298fea93c5b0b0834d Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 22 Apr 2022 12:02:33 -0700 Subject: Fix build with GCC12: apparently incorrect use-after-free warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GCC12 is complaining about a use-after-free here, but I don't see it. In member function ‘void QQmlContextData::release() const’, inlined from ‘QQmlRefPointer::~QQmlRefPointer() [with T = QQmlContextData]’ at ftw/qqmlrefcount_p.h:181:22, inlined from ‘bool {anonymous}::contextHasNoExtensions(const QQmlRefPointer&)’ at qqmlpropertycache.cpp:658:29, inlined from ‘const QQmlPropertyData* QQmlPropertyCache::findProperty(QLinkedStringMultiHash >::ConstIterator, const QQmlVMEMetaObject*, const QQmlRefPointer&) const’ at qqmlpropertycache.cpp:683:56: qqmlcontextdata_p.h:88:34: error: pointer used after ‘void operator delete(void*, std::size_t)’ [-Werror=use-after-free] 88 | void release() const { if (--m_refCount == 0) delete this; } | ^~~~~~~~~~ In member function ‘void QQmlContextData::release() const’, inlined from ‘QQmlRefPointer::~QQmlRefPointer() [with T = QQmlContextData]’ at ftw/qqmlrefcount_p.h:181:22, inlined from ‘bool {anonymous}::contextHasNoExtensions(const QQmlRefPointer&)’ at qqmlpropertycache.cpp:658:51, inlined from ‘const QQmlPropertyData* QQmlPropertyCache::findProperty(QLinkedStringMultiHash >::ConstIterator, const QQmlVMEMetaObject*, const QQmlRefPointer&) const’ at qqmlpropertycache.cpp:683:56: qqmlcontextdata_p.h:88:58: note: call to ‘void operator delete(void*, std::size_t)’ here 88 | void release() const { if (--m_refCount == 0) delete this; } | ^~~~ Change-Id: If05aeeb7176e4f13af9afffd16e84d54de676bc2 Reviewed-by: Ulf Hermann (cherry picked from commit cafc60c3bfb2d60360b9ca536430e829f2daae96) Reviewed-by: Qt Cherry-pick Bot --- src/qml/qml/qqmlpropertycache.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp index 69fa317495..5b44ead713 100644 --- a/src/qml/qml/qqmlpropertycache.cpp +++ b/src/qml/qml/qqmlpropertycache.cpp @@ -660,7 +660,8 @@ inline bool contextHasNoExtensions(const QQmlRefPointer &contex { // This context has no extension if its parent is the engine's rootContext, // which has children but no imports - return (!context->parent() || !context->parent()->imports()); + const QQmlRefPointer parent = context->parent(); + return (!parent || !parent->imports()); } inline int maximumIndexForProperty(QQmlPropertyData *prop, const int methodCount, const int signalCount, const int propertyCount) -- cgit v1.2.3