From 048e57baa5bdbc0dbccb4b0a2851a25c9c904280 Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Wed, 18 Jan 2012 07:06:59 -0600 Subject: [PATCH] fixes a crash while closing all connections, references #50 --- src/endpoint.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/endpoint.hpp b/src/endpoint.hpp index dbf3a8120a..178d5f09b1 100644 --- a/src/endpoint.hpp +++ b/src/endpoint.hpp @@ -207,10 +207,11 @@ public: << "Endpoint received signal to close all connections cleanly with code " << code << " and reason " << reason << log::endl; - typename std::set::iterator it; - - for (it = m_connections.begin(); it != m_connections.end(); it++) { - (*it)->close(code,reason); + // TODO: is there a more elegant way to do this? In some code paths + // close can call terminate immediately which removes the connection + // from m_connections, invalidating the iterator. + while(!m_connections.empty()) { + (m_connections->begin())->close(code,reason); } }