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 <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
David Edmundson 2022-02-09 13:22:15 +00:00
parent fe472ee0f4
commit e228149142

View File

@ -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);