diff options
author | Olivier Goffart <olivier.goffart@nokia.com> | 2011-03-25 18:15:39 (GMT) |
---|---|---|
committer | Olivier Goffart <olivier.goffart@nokia.com> | 2011-03-28 13:21:02 (GMT) |
commit | 0ee221b374ffef3657247be4c78e05689e04bef7 (patch) | |
tree | ed422aeaeca48be516e2a87867d0f7ca89c080a2 /tests/auto/qthread | |
parent | 383da4084ae0cd8dcb9777cbfa90a55c56f7ad09 (diff) | |
download | Qt-0ee221b374ffef3657247be4c78e05689e04bef7.zip Qt-0ee221b374ffef3657247be4c78e05689e04bef7.tar.gz Qt-0ee221b374ffef3657247be4c78e05689e04bef7.tar.bz2 |
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.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/auto/qthread/tst_qthread.cpp b/tests/auto/qthread/tst_qthread.cpp index c69052e..12709db 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() |