From 84b53c165e9d492a547c04499450007d2c293bc8 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Tue, 9 Jun 2020 11:24:55 +0200 Subject: tst_qqmlincubator: Reduce memory leaks This patch fixes memory leaks caused by the test itself. There are still memory leakes left in deleteSelf and requiredProperties; the latter might indicate an actual issue when the incubator fails due to required properties missing; this should be fixed (in another commit). deleteSelf is rather weird, and requires more investigation. Change-Id: I53f1da608c4bf6095d39fd573c6eeefcc9219c7c Reviewed-by: Ulf Hermann --- tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp | 31 +++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'tests/auto/qml/qqmlincubator') diff --git a/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp b/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp index 6c5416c784..1650a3a1d6 100644 --- a/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp +++ b/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp @@ -473,6 +473,13 @@ class Switcher : public QObject Q_OBJECT public: Switcher(QQmlEngine *e) : QObject(), engine(e) { } + ~Switcher() + { + if (component) + component->deleteLater(); + if (incubator && incubator->object()) + incubator->object()->deleteLater(); + } struct MyIncubator : public QQmlIncubator { @@ -489,13 +496,13 @@ public: void start() { - incubator = new MyIncubator(QQmlIncubator::Synchronous, this); + incubator.reset(new MyIncubator(QQmlIncubator::Synchronous, this)); component = new QQmlComponent(engine, QQmlDataTest::instance()->testFileUrl("recursiveClear.1.qml")); component->create(*incubator); } QQmlEngine *engine; - MyIncubator *incubator; + QScopedPointer incubator; QQmlComponent *component; public slots: @@ -594,18 +601,17 @@ void tst_qqmlincubator::asynchronousIfNested() QQmlComponent component(&engine, testFileUrl("asynchronousIfNested.1.qml")); QVERIFY(component.isReady()); - QObject *object = component.create(); - QVERIFY(object != nullptr); + QScopedPointer object { component.create() }; + QVERIFY(object); QCOMPARE(object->property("a").toInt(), 10); QQmlIncubator incubator(QQmlIncubator::AsynchronousIfNested); - component.create(incubator, nullptr, qmlContext(object)); + component.create(incubator, nullptr, qmlContext(object.get())); QVERIFY(incubator.isReady()); QVERIFY(incubator.object()); QCOMPARE(incubator.object()->property("a").toInt(), 10); delete incubator.object(); - delete object; } // Asynchronous if nested within an executing context behaves asynchronously, but prevents @@ -679,6 +685,7 @@ void tst_qqmlincubator::asynchronousIfNested() if (incubator.object()->property("a").toInt() != 10) return; d->pass = true; + incubator.object()->deleteLater(); } }; @@ -806,6 +813,9 @@ void tst_qqmlincubator::chainedAsynchronousIfNested() QVERIFY(incubator.isReady()); QVERIFY(incubator1.isReady()); QVERIFY(incubator2.isReady()); + incubator.object()->deleteLater(); + incubator1.object()->deleteLater(); + incubator2.object()->deleteLater(); } // Checks that new AsynchronousIfNested incubators can be correctly chained if started in @@ -934,6 +944,11 @@ void tst_qqmlincubator::chainedAsynchronousIfNestedOnCompleted() QVERIFY(incubator1.isReady()); QVERIFY(incubator2.isReady()); QVERIFY(incubator3.isReady()); + + incubator.object()->deleteLater(); + incubator1.object()->deleteLater(); + incubator2.object()->deleteLater(); + incubator3.object()->deleteLater(); } // Checks that new AsynchronousIfNested incubators can be correctly cleared if started in @@ -1050,6 +1065,10 @@ void tst_qqmlincubator::chainedAsynchronousClear() QVERIFY(incubator1.isReady()); QVERIFY(incubator2.isReady()); QVERIFY(incubator3.isNull()); + + + incubator1.object()->deleteLater(); + incubator2.object()->deleteLater(); } void tst_qqmlincubator::selfDelete() -- cgit v1.2.3