summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJohan Klokkhammer Helsing <johan.helsing@qt.io>2017-08-30 14:00:51 +0200
committerJohan Helsing <johan.helsing@qt.io>2017-08-31 09:50:51 +0000
commit3e745ea053e42ba087438203df3bd76b30a08eb2 (patch)
treea290f8a2aff959de025dcae3268a5d78ed0bbd1d /tests
parent97683fd367d9a42aeb6caadad5daa8e07412469e (diff)
downloadqtwayland-3e745ea053e42ba087438203df3bd76b30a08eb2.tar.gz
Fix crash when window attach is called without waiting for frame callbacks
If QWaylandWindow::attach was called before getting the frame callback, it would overwrite mFrameCallback. Hence, all but the last frame callback would still be alive after the QWaylandWindow destructor. When the dangling callbacks got invoked the data pointer was statically casted to the deleted QWaylandWindow, resulting in undefined behavior. In this change we only delete frame callbacks from the render thread, avoiding a race condition we fixed earlier. And we always destroy the frame callback when adding a new one, ensuring that the destructor will clean up the only remaining callback. There's a test confirming that the crash has been fixed. This fixes the flakiness of many of the qtbase auto tests. Change-Id: Iecb08ab48216eac61b1ebc5c0e0664d4aac900c0 Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/client/client/tst_client.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/auto/client/client/tst_client.cpp b/tests/auto/client/client/tst_client.cpp
index 0c9c007a..8acddfbe 100644
--- a/tests/auto/client/client/tst_client.cpp
+++ b/tests/auto/client/client/tst_client.cpp
@@ -142,6 +142,7 @@ private slots:
void backingStore();
void touchDrag();
void mouseDrag();
+ void dontCrashOnMultipleCommits();
private:
MockCompositor *compositor;
@@ -333,6 +334,32 @@ void tst_WaylandClient::mouseDrag()
QTRY_VERIFY(window.dragStarted);
}
+void tst_WaylandClient::dontCrashOnMultipleCommits()
+{
+ auto window = new TestWindow();
+ window->show();
+
+ QRect rect(QPoint(), window->size());
+
+ QBackingStore backingStore(window);
+ backingStore.resize(rect.size());
+ backingStore.beginPaint(rect);
+ QPainter p(backingStore.paintDevice());
+ p.fillRect(rect, Qt::magenta);
+ p.end();
+ backingStore.endPaint();
+
+ backingStore.flush(rect);
+ backingStore.flush(rect);
+ backingStore.flush(rect);
+
+ compositor->processWaylandEvents();
+
+ delete window;
+
+ QTRY_VERIFY(!compositor->surface());
+}
+
int main(int argc, char **argv)
{
setenv("XDG_RUNTIME_DIR", ".", 1);