Reference resources to prevent crash (on some platforms)
authorAaron Kennedy <aaron.kennedy@nokia.com>
Tue, 26 Jul 2011 01:32:09 +0000 (11:32 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 26 Jul 2011 04:29:54 +0000 (06:29 +0200)
Prevent the data blob from being deleted in done().

Task-number: QTBUG-18268

Change-Id: Ib265e6fc3e1539d0baf20e365c1f88f615b121dc
Reviewed-on: http://codereview.qt.nokia.com/2138
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
src/declarative/qml/qdeclarativetypeloader.cpp
tests/auto/declarative/qdeclarativelanguage/data/remoteLoadCrash.qml [new file with mode: 0644]
tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp

index 47c90bd..cb3e8ae 100644 (file)
@@ -379,8 +379,10 @@ void QDeclarativeDataBlob::tryDone()
             m_status = Complete;
 
         m_isDone = true;
+        addref();
         done();
         notifyAllWaitingOnMe();
+        release();
     }
 }
 
diff --git a/tests/auto/declarative/qdeclarativelanguage/data/remoteLoadCrash.qml b/tests/auto/declarative/qdeclarativelanguage/data/remoteLoadCrash.qml
new file mode 100644 (file)
index 0000000..d96a31f
--- /dev/null
@@ -0,0 +1,3 @@
+import QtQuick 1.0
+Text {
+}
index 328b7c8..dfaf3d1 100644 (file)
@@ -160,6 +160,7 @@ private slots:
     void revisionOverloads();
 
     void propertyInit();
+    void remoteLoadCrash();
 
     // regression tests for crashes
     void crash1();
@@ -2069,6 +2070,21 @@ void tst_qdeclarativelanguage::registrationOrder()
     delete o;
 }
 
+// QTBUG-18268
+void tst_qdeclarativelanguage::remoteLoadCrash()
+{
+    TestHTTPServer server(14448);
+    server.serveDirectory(SRCDIR);
+
+    QDeclarativeComponent component(&engine);
+    component.setData("import QtQuick 1.0; Text {}", QUrl("http://127.0.0.1:14448/data/remoteLoadCrash.qml"));
+    while (component.isLoading()) 
+        QCoreApplication::processEvents( QEventLoop::ExcludeUserInputEvents | QEventLoop::WaitForMoreEvents, 50);
+
+    QObject *o = component.create();
+    delete o;
+}
+
 QTEST_MAIN(tst_qdeclarativelanguage)
 
 #include "tst_qdeclarativelanguage.moc"