From 6e2bbd5bdcbd89e0ed2055ea7c3f4ab20bfb6acf Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Wed, 6 Sep 2017 22:18:41 +0200 Subject: [PATCH] rcinput: fix corrupted iterator on input device hot-unplug Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/36951c814115a70ed163d3dd4f3cd9f2b94d0401 Author: Stefan Seyfried Date: 2017-09-06 (Wed, 06 Sep 2017) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- src/driver/rcinput.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/driver/rcinput.cpp b/src/driver/rcinput.cpp index f2455010f..5080ca632 100644 --- a/src/driver/rcinput.cpp +++ b/src/driver/rcinput.cpp @@ -1304,7 +1304,10 @@ void CRCInput::getMsg_us(neutrino_msg_t * msg, neutrino_msg_data_t * data, uint6 } } - for (std::vector::iterator i = indev.begin(); i != indev.end(); ++i) { + /* iterate backwards or the vector will be corrupted by the indev.erase(i) */ + std::vector::iterator i = indev.end(); + while (i != indev.begin()) { + --i; if (((*i).fd != -1) && (FD_ISSET((*i).fd, &rfds))) { uint64_t now_pressed = 0; t_input_event ev; @@ -1316,7 +1319,7 @@ void CRCInput::getMsg_us(neutrino_msg_t * msg, neutrino_msg_data_t * data, uint6 if (errno == ENODEV) { /* hot-unplugged? */ ::close((*i).fd); - indev.erase(i); + i = indev.erase(i); } continue; }