Skip to content

Commit

Permalink
Loader could leak qml contexts if interrupted
Browse files Browse the repository at this point in the history
If Loader was either destroyed, or its source changed while
it was incubating the itemContext could be leaked.

Change-Id: I5b749062552954d92bf2851250f942b20ebbfe68
Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>
  • Loading branch information
Martin Jones authored and Qt by Nokia committed Mar 20, 2012
1 parent 01f0966 commit 0ecadd9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/quick/items/qquickloader.cpp
Expand Up @@ -61,6 +61,8 @@ QQuickLoaderPrivate::QQuickLoaderPrivate()

QQuickLoaderPrivate::~QQuickLoaderPrivate()
{
delete itemContext;
itemContext = 0;
delete incubator;
disposeInitialPropertyValues();
}
Expand All @@ -79,12 +81,21 @@ void QQuickLoaderPrivate::itemGeometryChanged(QQuickItem *resizeItem, const QRec

void QQuickLoaderPrivate::clear()
{
Q_Q(QQuickLoader);
disposeInitialPropertyValues();

if (incubator)
incubator->clear();

delete itemContext;
itemContext = 0;

if (loadingFromSource && component) {
// disconnect since we deleteLater
QObject::disconnect(component, SIGNAL(statusChanged(QQmlComponent::Status)),
q, SLOT(_q_sourceLoaded()));
QObject::disconnect(component, SIGNAL(progressChanged(qreal)),
q, SIGNAL(progressChanged()));
component->deleteLater();
component = 0;
}
Expand Down Expand Up @@ -545,6 +556,7 @@ void QQuickLoaderPrivate::setInitialState(QObject *obj)
QQml_setParent_noEvent(itemContext, obj);
QQml_setParent_noEvent(item, q);
item->setParentItem(q);
itemContext = 0;
}

if (initialPropertyValues.IsEmpty())
Expand Down
6 changes: 4 additions & 2 deletions tests/auto/quick/qquickloader/tst_qquickloader.cpp
Expand Up @@ -929,7 +929,7 @@ void tst_QQuickLoader::asynchronous_clear()
QVERIFY(!loader->item());

QCOMPARE(loader->status(), QQuickLoader::Loading);
QCOMPARE(engine.incubationController()->incubatingObjectCount(), 1);
QTRY_COMPARE(engine.incubationController()->incubatingObjectCount(), 1);

// clear before component created
root->setProperty("comp", "");
Expand All @@ -942,7 +942,7 @@ void tst_QQuickLoader::asynchronous_clear()
QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 0);

// check loading component
root->setProperty("comp", "Rect120x60.qml");
root->setProperty("comp", "BigComponent.qml");
QMetaObject::invokeMethod(root, "loadComponent");
QVERIFY(!loader->item());

Expand All @@ -953,6 +953,8 @@ void tst_QQuickLoader::asynchronous_clear()
QCOMPARE(loader->progress(), 1.0);
QCOMPARE(loader->status(), QQuickLoader::Ready);
QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 1);

delete root;
}

void tst_QQuickLoader::simultaneousSyncAsync()
Expand Down

0 comments on commit 0ecadd9

Please sign in to comment.