From adb58f8cd390e43e0821f16f0b502a2956731305 Mon Sep 17 00:00:00 2001 From: Benoit Foucher Date: Thu, 2 Feb 2006 14:29:19 +0000 Subject: Fixed memory corruption problem --- cpp/src/IceGrid/NodeCache.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'cpp/src/IceGrid/NodeCache.cpp') diff --git a/cpp/src/IceGrid/NodeCache.cpp b/cpp/src/IceGrid/NodeCache.cpp index c3022bf0c9a..d5c034cfb8e 100644 --- a/cpp/src/IceGrid/NodeCache.cpp +++ b/cpp/src/IceGrid/NodeCache.cpp @@ -162,7 +162,8 @@ NodeCache::NodeCache(int sessionTimeout) : _sessionTimeout(sessionTimeout) void NodeCache::destroy() { - for(map::const_iterator p = _entries.begin(); p != _entries.end(); ++p) + map entries = _entries; // Copying the map is necessary as setSession might remove the entry. + for(map::const_iterator p = entries.begin(); p != entries.end(); ++p) { p->second->setSession(0); // Break cyclic reference count. } @@ -246,10 +247,6 @@ NodeEntry::setSession(const NodeSessionIPtr& session) _session = session; remove = _servers.empty() && !_session && _descriptors.empty(); } - if(remove) - { - _cache.remove(_name); - } if(session) { @@ -277,6 +274,15 @@ NodeEntry::setSession(const NodeSessionIPtr& session) out << "node `" << _name << "' down"; } } + + // + // NOTE: this needs to be the last thing to do as this will + // destroy this entry. + // + if(remove) + { + _cache.remove(_name); + } } NodePrx -- cgit v1.2.3