Erasure of retired fd's in select.cpp causes an assertion in MSVC 2008 STL

I was hitting an issue with an SCL enabled STL library in connection with the
way select_t::loop was erasing retired fd's. The problem as identified by the
SCL assertion was that by the time the iterator given to the erase method was
called it was considered invalid by the library. I am not sure this isn't just
a "quirk" of the MSVC STL library as the other code looks valid to me as well.
This commit is contained in:
Mikael Helbo Kjær 2010-09-01 18:39:12 +02:00 committed by Martin Sustrik
parent 99ddfa7d65
commit 59315ebdcb

View File

@ -217,10 +217,13 @@ void zmq::select_t::loop ()
// Destroy retired event sources.
if (retired) {
for (fd_set_t::size_type i = 0; i < fds.size (); i ++) {
if (fds [i].fd == retired_fd) {
fds.erase (fds.begin () + i);
i --;
fd_set_t::iterator it = fds.begin();
while (it != fds.end()) {
if (it->fd == retired_fd) {
it = fds.erase(it);
}
else {
it++;
}
}
retired = false;