From 089ee8ac0ab2a0e1801bfe99e0e799aa7a19b8d6 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 1 Dec 2016 20:55:28 +0000 Subject: [PATCH] Fix crash when quitting the first client while another client is connected --- src/client_manager.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/client_manager.cc b/src/client_manager.cc index 97ace9e1..f2989b90 100644 --- a/src/client_manager.cc +++ b/src/client_manager.cc @@ -71,8 +71,12 @@ void ClientManager::process_pending_inputs() const while (true) { bool had_input = false; - for (auto& client : m_clients) - had_input = client->process_pending_inputs() or had_input; + // Use index based iteration as a m_clients might get mutated during + // client input processing, which would break iterator based iteration. + // (its fine to skip a client if that happens as had_input will be true + // if a client triggers client removal) + for (int i = 0; i < m_clients.size(); ++i) + had_input = m_clients[i]->process_pending_inputs() or had_input; if (not had_input) break;