From 68c4615c9f0c37d3debfdace0c2169103cf9287d Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Fri, 28 Sep 2007 17:53:16 +0000 Subject: Ensure no danbling pointers in client API: - Session -shared_ptr-> SessionCore -shared_ptr-> ConnectionImpl - Connection -shared_ptr-> ConnectionImpl - ConnectionImpl -weak_ptr-> SessionCore git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@580440 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/client/ConnectionImpl.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'cpp/src/qpid/client/ConnectionImpl.cpp') diff --git a/cpp/src/qpid/client/ConnectionImpl.cpp b/cpp/src/qpid/client/ConnectionImpl.cpp index 43576d2273..fae93e8294 100644 --- a/cpp/src/qpid/client/ConnectionImpl.cpp +++ b/cpp/src/qpid/client/ConnectionImpl.cpp @@ -45,8 +45,8 @@ ConnectionImpl::ConnectionImpl(boost::shared_ptr c) void ConnectionImpl::addSession(const boost::shared_ptr& session) { Mutex::ScopedLock l(lock); - boost::shared_ptr& s = sessions[session->getChannel()]; - if (s) + boost::weak_ptr& s = sessions[session->getChannel()]; + if (s.lock()) throw ChannelBusyException(); s = session; } @@ -61,7 +61,7 @@ void ConnectionImpl::incoming(framing::AMQFrame& frame) boost::shared_ptr s; { Mutex::ScopedLock l(lock); - s = sessions[frame.getChannel()]; + s = sessions[frame.getChannel()].lock(); } if (!s) throw ChannelErrorException(); @@ -120,7 +120,9 @@ void ConnectionImpl::signalClose(uint16_t code, const std::string& text) { Mutex::ScopedLock l(lock); for (SessionMap::iterator i = sessions.begin(); i != sessions.end(); i++) { - i->second->closed(code, text); + boost::shared_ptr s = i->second.lock(); + if (s) + s->closed(code, text); } sessions.clear(); isClosed = true; -- cgit v1.2.1