diff options
author | Peter Kümmel <syntheticpp@gmx.net> | 2012-12-01 11:03:03 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-12-17 14:08:17 +0100 |
commit | a42ad77ec9a13005041c01516a2bed8e05fad6fa (patch) | |
tree | aac1339eeff824514e36a4296f72140ecfe25ca8 | |
parent | 63693430c7cb8e8ede611eb9e99f305370d11ff9 (diff) |
Fix possible crash in tst_QThread::quitLock() test
Don't read member variable of deleted Job object.
Change-Id: I71a6565c4932427e9cbab744c2e472b62ea98ca2
Reviewed-by: Andreas Aardal Hanssen <andreas@hanssen.name>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | tests/auto/corelib/thread/qthread/tst_qthread.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/tests/auto/corelib/thread/qthread/tst_qthread.cpp b/tests/auto/corelib/thread/qthread/tst_qthread.cpp index bdfb980357..eaae3d49d3 100644 --- a/tests/auto/corelib/thread/qthread/tst_qthread.cpp +++ b/tests/auto/corelib/thread/qthread/tst_qthread.cpp @@ -1300,9 +1300,10 @@ class Job : public QObject { Q_OBJECT public: - Job(QThread *thread, int deleteDelay, QObject *parent = 0) - : QObject(parent), quitLocker(thread), exitThreadCalled(false) + Job(QThread *thread, int deleteDelay, bool *flag, QObject *parent = 0) + : QObject(parent), quitLocker(thread), exitThreadCalled(*flag) { + exitThreadCalled = false; moveToThread(thread); QTimer::singleShot(deleteDelay, this, SLOT(deleteLater())); QTimer::singleShot(1000, this, SLOT(exitThread())); @@ -1318,12 +1319,13 @@ private slots: private: QEventLoopLocker quitLocker; public: - bool exitThreadCalled; + bool &exitThreadCalled; }; void tst_QThread::quitLock() { QThread thread; + bool exitThreadCalled; QEventLoop loop; connect(&thread, SIGNAL(finished()), &loop, SLOT(quit())); @@ -1331,16 +1333,16 @@ void tst_QThread::quitLock() Job *job; thread.start(); - job = new Job(&thread, 500); + job = new Job(&thread, 500, &exitThreadCalled); QCOMPARE(job->thread(), &thread); loop.exec(); - QVERIFY(!job->exitThreadCalled); + QVERIFY(!exitThreadCalled); thread.start(); - job = new Job(&thread, 2500); + job = new Job(&thread, 2500, &exitThreadCalled); QCOMPARE(job->thread(), &thread); loop.exec(); - QVERIFY(job->exitThreadCalled); + QVERIFY(exitThreadCalled); } QTEST_MAIN(tst_QThread) |