summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2013-07-09 15:31:26 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-07-10 17:57:10 +0200
commitd6d9edd7c47b183edc1acc631602ea4f4a885d84 (patch)
treed9e58995cb2c59810a9a51c2298c36ee0a742203 /tests
parente07bdb8f7401f207a1637d2c2efd299db31756ed (diff)
Fix dead lock in the Qt event handling
The deadlock is caused because the QEvent is destroyed while holding the event list mutex. And the QEvent may have a custom destructor that will re-enter the event handlng code. The QScopedPointer that should destroy the event must be created after the MutexUnlocker. Regression introduced by commit f9035587b98ac5dc9491e642b8ec84470ec03f0e Task-number: QTBUG-31606 Change-Id: I6b2cbc2656eacdec61b641886953f00bf5b3ff36 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp
index ff1d8b2a36..ccaa2bec4f 100644
--- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp
+++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp
@@ -69,6 +69,7 @@ private slots:
void eventLoopExecAfterExit();
void customEventDispatcher();
void testQuitLock();
+ void QTBUG31606_QEventDestructorDeadLock();
};
class EventSpy : public QObject
@@ -769,6 +770,33 @@ void tst_QCoreApplication::testQuitLock()
app.exec();
}
+
+void tst_QCoreApplication::QTBUG31606_QEventDestructorDeadLock()
+{
+ class MyEvent : public QEvent
+ { public:
+ MyEvent() : QEvent(QEvent::Type(QEvent::User + 1)) {}
+ ~MyEvent() {
+ QCoreApplication::postEvent(qApp, new QEvent(QEvent::Type(QEvent::User+2)));
+ }
+ };
+
+ int argc = 1;
+ char *argv[] = { const_cast<char*>("tst_qcoreapplication") };
+ QCoreApplication app(argc, argv);
+
+ EventSpy spy;
+ app.installEventFilter(&spy);
+
+ QCoreApplication::postEvent(&app, new MyEvent);
+ QCoreApplication::processEvents();
+ QVERIFY(spy.recordedEvents.contains(QEvent::User + 1));
+ QVERIFY(!spy.recordedEvents.contains(QEvent::User + 2));
+ QCoreApplication::processEvents();
+ QVERIFY(spy.recordedEvents.contains(QEvent::User + 2));
+}
+
+
static void createQObjectOnDestruction()
{
// Make sure that we can create a QObject after the last QObject has been