summaryrefslogtreecommitdiffstats
path: root/tests/auto/qthread
diff options
context:
space:
mode:
authorOlivier Goffart <olivier.goffart@nokia.com>2011-03-25 19:15:39 +0100
committerOlivier Goffart <olivier.goffart@nokia.com>2011-03-28 15:21:02 +0200
commit0ee221b374ffef3657247be4c78e05689e04bef7 (patch)
treeed422aeaeca48be516e2a87867d0f7ca89c080a2 /tests/auto/qthread
parent383da4084ae0cd8dcb9777cbfa90a55c56f7ad09 (diff)
Fix the leak of QAdoptedThread and all dependent objects
if there is a QEventDispatcher in QAdoptedThread. QAdoptedThread is supposed to be destroyed when the QThreadData is destroyed. But QThreadData is ref-counted, and QEventDispatcher holds a reference to it. QEventDispatcher is supposed to be destroyed in QThreadPrivate::finish, which is supposed to be called from the destructor of QAdoptedThread. There is a circular dependence. We break it by calling finish in the callback that is called when the thread is finished. Task-number: QTBUG-17986 Reviewed-by: Brad
Diffstat (limited to 'tests/auto/qthread')
-rw-r--r--tests/auto/qthread/tst_qthread.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/auto/qthread/tst_qthread.cpp b/tests/auto/qthread/tst_qthread.cpp
index c69052ee7d..12709dbe94 100644
--- a/tests/auto/qthread/tst_qthread.cpp
+++ b/tests/auto/qthread/tst_qthread.cpp
@@ -103,6 +103,7 @@ private slots:
void adoptedThreadExit();
void adoptedThreadExec();
void adoptedThreadFinished();
+ void adoptedThreadExecFinished();
void adoptMultipleThreads();
void QTBUG13810_exitAndStart();
@@ -895,6 +896,21 @@ void tst_QThread::adoptedThreadFinished()
QVERIFY(!QTestEventLoop::instance().timeout());
}
+void tst_QThread::adoptedThreadExecFinished()
+{
+ NativeThreadWrapper nativeThread;
+ nativeThread.setWaitForStop();
+ nativeThread.startAndWait(adoptedThreadExecFunction);
+
+ QObject::connect(nativeThread.qthread, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
+
+ nativeThread.stop();
+ nativeThread.join();
+
+ QTestEventLoop::instance().enterLoop(5);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+}
+
void tst_QThread::adoptMultipleThreads()
{
#if defined(Q_OS_WIN)
@@ -929,6 +945,7 @@ void tst_QThread::adoptMultipleThreads()
QTestEventLoop::instance().enterLoop(5);
QVERIFY(!QTestEventLoop::instance().timeout());
QCOMPARE(int(recorder.activationCount), numThreads);
+ qDeleteAll(nativeThreads);
}
void tst_QThread::stressTest()