diff --git a/src/driver/rcinput.cpp b/src/driver/rcinput.cpp index 0d19b46d1..35e983034 100644 --- a/src/driver/rcinput.cpp +++ b/src/driver/rcinput.cpp @@ -1302,7 +1302,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; @@ -1314,7 +1317,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; }