Skip to content

Commit

Permalink
Fix iterator invalidation in hub.cc
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuo committed Nov 20, 2013
1 parent f2129c6 commit 3bc57ca
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions examples/hub/hub.cc
Expand Up @@ -97,11 +97,11 @@ class PubSubServer : boost::noncopyable
{
const ConnectionSubscription& connSub
= boost::any_cast<const ConnectionSubscription&>(conn->getContext());
// subtle: doUnsubscribe will erase *it, so increase before calling.
for (ConnectionSubscription::const_iterator it = connSub.begin();
it != connSub.end();
++it)
it != connSub.end();)
{
doUnsubscribe(conn, *it);
doUnsubscribe(conn, *it++);
}
}
}
Expand Down Expand Up @@ -165,10 +165,11 @@ class PubSubServer : boost::noncopyable
const string& topic)
{
LOG_INFO << conn->name() << " unsubscribes " << topic;
getTopic(topic).remove(conn);
// topic could be the one to be destroyed, so don't use it after erasing.
ConnectionSubscription* connSub
= boost::any_cast<ConnectionSubscription>(conn->getMutableContext());
connSub->erase(topic);
getTopic(topic).remove(conn);
}

void doPublish(const string& source,
Expand Down

0 comments on commit 3bc57ca

Please sign in to comment.