diff options
author | Martin Jones <martin.jones@nokia.com> | 2011-11-30 09:44:13 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-11-30 04:34:34 +0100 |
commit | 9321a19664ca7409f599b68e3784bbd5bd321a54 (patch) | |
tree | a0f1a17154db66cb95611c1ea11f83f4b01c5a4c /tests | |
parent | a782a3e5d6c73aaa8de065452349a7b925c0faf9 (diff) |
Deleting an incubated object after setInitialState() crashes
Incubating objects are often parented in setInitialState(), which
can lead to the incubating object being deleted after object creation,
but before completion. When incubator.clear() is called after
this point, it would attempt to delete the already deleted
object. This change guards the incubation object in the incubator.
Change-Id: I9585e93027250b8b6b3f1777b10ee1008ae7b818
Reviewed-by: Glenn Watson <glenn.watson@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp b/tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp index 74a6b83bf4..fe618b87e8 100644 --- a/tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp +++ b/tests/auto/declarative/qdeclarativeincubator/tst_qdeclarativeincubator.cpp @@ -79,6 +79,7 @@ private slots: void forceCompletion(); void setInitialState(); void clearDuringCompletion(); + void objectDeletionAfterInit(); void recursiveClear(); void statusChanged(); void asynchronousIfNested(); @@ -434,6 +435,42 @@ void tst_qdeclarativeincubator::clearDuringCompletion() QVERIFY(srt.isNull()); } +void tst_qdeclarativeincubator::objectDeletionAfterInit() +{ + QDeclarativeComponent component(&engine, TEST_FILE("clear.qml")); + QVERIFY(component.isReady()); + + struct MyIncubator : public QDeclarativeIncubator + { + MyIncubator(QDeclarativeIncubator::IncubationMode mode) + : QDeclarativeIncubator(mode), obj(0) {} + + virtual void setInitialState(QObject *o) { + obj = o; + } + + QObject *obj; + }; + + SelfRegisteringType::clearMe(); + MyIncubator incubator(QDeclarativeIncubator::Asynchronous); + component.create(incubator); + + while (!incubator.obj && incubator.isLoading()) { + bool b = false; + controller.incubateWhile(&b); + } + + QVERIFY(incubator.isLoading()); + QVERIFY(SelfRegisteringType::me() != 0); + + delete incubator.obj; + + incubator.clear(); + QCoreApplication::processEvents(QEventLoop::DeferredDeletion); + QVERIFY(incubator.isNull()); +} + class Switcher : public QObject { Q_OBJECT |