From 59315ebdcb565d23ba78ba0ca8581cef465fc9bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20Helbo=20Kj=C3=A6r?= Date: Wed, 1 Sep 2010 18:39:12 +0200 Subject: 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. --- src/select.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/select.cpp b/src/select.cpp index be5cd47..7345cbb 100644 --- a/src/select.cpp +++ b/src/select.cpp @@ -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; -- cgit v1.2.3