From e2281491420edb35fb8f203b8af7b18fb2e94658 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Wed, 9 Feb 2022 13:22:15 +0000 Subject: [PATCH] client: Avoid trying to read/cancel read if wl_display_read_events failed wl_display_prepare_read and wl_display_read_events/wl_display_cancel_read must come as matching pairs. Otherwise we set libwayland's internal read count to a negative number and causes all types of deadlocks. If prepareReadQueue fails but we haven't explicitly quit waitForReading returns a success statement but we haven't opened anything. Pragmatically most times wl_display_prepare_read fails it's because of a wayland error which is handled by exiting anyway, but it is better to err on the side of safety. Change-Id: Ia29c3217622d97594404be3daf4c50338a1d3fb0 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/plugins/platforms/wayland/qwaylanddisplay.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/plugins/platforms/wayland/qwaylanddisplay.cpp b/src/plugins/platforms/wayland/qwaylanddisplay.cpp index 79c68a93201..2c275a92e22 100644 --- a/src/plugins/platforms/wayland/qwaylanddisplay.cpp +++ b/src/plugins/platforms/wayland/qwaylanddisplay.cpp @@ -216,6 +216,9 @@ protected: // Make the main thread call wl_prepare_read(), dispatch the pending messages and flush the // outbound ones. Wait until it's done before proceeding, unless we're told to quit. while (waitForReading()) { + if (!m_reading.loadRelaxed()) + break; + pollfd fds[2] = { { m_fd, POLLIN, 0 }, { m_pipefd[0], POLLIN, 0 } }; poll(fds, 2, -1);