From 21352eda9ad76aa01dced70032291303fd12e714 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Wed, 19 May 2010 10:21:05 +0000 Subject: Prevent race between shutdown() and release() resulting in attempt to close deleted connector. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@946106 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/qpid/client/ConnectionImpl.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'qpid/cpp/src') diff --git a/qpid/cpp/src/qpid/client/ConnectionImpl.cpp b/qpid/cpp/src/qpid/client/ConnectionImpl.cpp index 63a21c1205..d5fe7489d3 100644 --- a/qpid/cpp/src/qpid/client/ConnectionImpl.cpp +++ b/qpid/cpp/src/qpid/client/ConnectionImpl.cpp @@ -371,15 +371,24 @@ void ConnectionImpl::release() { bool isActive; { Mutex::ScopedLock l(lock); - released = true; isActive = connector && !shutdownComplete; } //If we are still active - i.e. associated with an IO thread - //then we cannot delete ourselves yet, but must wait for the //shutdown callback which we can trigger by calling //connector.close() - if (isActive) connector->close(); - else delete this; + if (isActive) { + connector->close(); + bool canDelete; + { + Mutex::ScopedLock l(lock); + released = true; + canDelete = shutdownComplete; + } + if (canDelete) delete this; + } else { + delete this; + } } static const std::string CONN_CLOSED("Connection closed"); -- cgit v1.2.1