aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2023-02-14 12:24:55 +0100
committerUlf Hermann <ulf.hermann@qt.io>2023-02-15 16:49:00 +0100
commit5001df10a10481cb93aac12b9350bd49a5d40e0f (patch)
tree17348be961864991cf6da43283bd6d19ae4abe29
parent4501cda657a989adb550a2a92ff4387e2274d7b7 (diff)
QQmlMetaType: Clear property caches on qmlClearTypeRegistrations
Otherwise we may retain dangling pointers referencing invalid property caches. Some metaobjects are created on the heap. If the memory manager decides to re-use the heap space for new metaobjects, we can retrieve the invalid property caches. Task-number: QTBUG-110933 Change-Id: Ic00bb852151bcf58ba6ae798a6bf2cea686a9e10 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 6937f2e50dd60c58350a464eb83ba9d11c7146f9) Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
-rw-r--r--src/qml/qml/qqmlmetatype.cpp1
-rw-r--r--tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp14
2 files changed, 15 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp
index 9245a03cc6..10f0a6f438 100644
--- a/src/qml/qml/qqmlmetatype.cpp
+++ b/src/qml/qml/qqmlmetatype.cpp
@@ -311,6 +311,7 @@ void QQmlMetaType::clearTypeRegistrations()
data->urlToNonFileImportType.clear();
data->metaObjectToType.clear();
data->undeletableTypes.clear();
+ data->propertyCaches.clear();
}
int QQmlMetaType::registerAutoParentFunction(const QQmlPrivate::RegisterAutoParent &function)
diff --git a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp
index 6f4221539d..1304930583 100644
--- a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp
+++ b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp
@@ -49,6 +49,8 @@ private slots:
void enumsInRecursiveImport_data();
void enumsInRecursiveImport();
+
+ void clearPropertyCaches();
};
class TestType : public QObject
@@ -711,6 +713,18 @@ void tst_qqmlmetatype::enumsInRecursiveImport()
QTRY_COMPARE(obj->property("color").toString(), QString("green"));
}
+void tst_qqmlmetatype::clearPropertyCaches()
+{
+ qmlClearTypeRegistrations();
+ qmlRegisterType<TestType>("ClearPropertyCaches", 1, 0, "A");
+ QQmlPropertyCache::ConstPtr oldCache = QQmlMetaType::propertyCache(&TestType::staticMetaObject);
+ QVERIFY(oldCache);
+ qmlClearTypeRegistrations();
+ qmlRegisterType<TestType>("ClearPropertyCaches", 1, 0, "B");
+ QQmlPropertyCache::ConstPtr newCache = QQmlMetaType::propertyCache(&TestType::staticMetaObject);
+ QVERIFY(oldCache.data() != newCache.data());
+}
+
QTEST_MAIN(tst_qqmlmetatype)
#include "tst_qqmlmetatype.moc"