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>
This commit is contained in:
parent
63693430c7
commit
a42ad77ec9
@ -1300,9 +1300,10 @@ class Job : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Job(QThread *thread, int deleteDelay, QObject *parent = 0)
|
Job(QThread *thread, int deleteDelay, bool *flag, QObject *parent = 0)
|
||||||
: QObject(parent), quitLocker(thread), exitThreadCalled(false)
|
: QObject(parent), quitLocker(thread), exitThreadCalled(*flag)
|
||||||
{
|
{
|
||||||
|
exitThreadCalled = false;
|
||||||
moveToThread(thread);
|
moveToThread(thread);
|
||||||
QTimer::singleShot(deleteDelay, this, SLOT(deleteLater()));
|
QTimer::singleShot(deleteDelay, this, SLOT(deleteLater()));
|
||||||
QTimer::singleShot(1000, this, SLOT(exitThread()));
|
QTimer::singleShot(1000, this, SLOT(exitThread()));
|
||||||
@ -1318,12 +1319,13 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
QEventLoopLocker quitLocker;
|
QEventLoopLocker quitLocker;
|
||||||
public:
|
public:
|
||||||
bool exitThreadCalled;
|
bool &exitThreadCalled;
|
||||||
};
|
};
|
||||||
|
|
||||||
void tst_QThread::quitLock()
|
void tst_QThread::quitLock()
|
||||||
{
|
{
|
||||||
QThread thread;
|
QThread thread;
|
||||||
|
bool exitThreadCalled;
|
||||||
|
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
connect(&thread, SIGNAL(finished()), &loop, SLOT(quit()));
|
connect(&thread, SIGNAL(finished()), &loop, SLOT(quit()));
|
||||||
@ -1331,16 +1333,16 @@ void tst_QThread::quitLock()
|
|||||||
Job *job;
|
Job *job;
|
||||||
|
|
||||||
thread.start();
|
thread.start();
|
||||||
job = new Job(&thread, 500);
|
job = new Job(&thread, 500, &exitThreadCalled);
|
||||||
QCOMPARE(job->thread(), &thread);
|
QCOMPARE(job->thread(), &thread);
|
||||||
loop.exec();
|
loop.exec();
|
||||||
QVERIFY(!job->exitThreadCalled);
|
QVERIFY(!exitThreadCalled);
|
||||||
|
|
||||||
thread.start();
|
thread.start();
|
||||||
job = new Job(&thread, 2500);
|
job = new Job(&thread, 2500, &exitThreadCalled);
|
||||||
QCOMPARE(job->thread(), &thread);
|
QCOMPARE(job->thread(), &thread);
|
||||||
loop.exec();
|
loop.exec();
|
||||||
QVERIFY(job->exitThreadCalled);
|
QVERIFY(exitThreadCalled);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QThread)
|
QTEST_MAIN(tst_QThread)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user