summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2011-11-20 02:29:13 -0500
committerEliot Horowitz <eliot@10gen.com>2011-11-21 01:01:33 -0500
commit163a0ede78d1dcbde86346248ff993db876f2a03 (patch)
tree57685f1a85755a5a476ae692669b017c25b14e7b
parent3a57f18f763ee0628badf8375dc41add957eaa67 (diff)
downloadmongo-163a0ede78d1dcbde86346248ff993db876f2a03.tar.gz
don't leak connections when onCreate or onHandOut hook fails SERVER-4331
-rw-r--r--client/connpool.cpp28
-rw-r--r--s/shardconnection.cpp8
2 files changed, 30 insertions, 6 deletions
diff --git a/client/connpool.cpp b/client/connpool.cpp
index 8f40a1d15d8..94ce4ec4eaa 100644
--- a/client/connpool.cpp
+++ b/client/connpool.cpp
@@ -145,9 +145,15 @@ namespace mongo {
PoolForHost& p = _pools[PoolKey(host,socketTimeout)];
p.createdOne( conn );
}
-
- onCreate( conn );
- onHandedOut( conn );
+
+ try {
+ onCreate( conn );
+ onHandedOut( conn );
+ }
+ catch ( std::exception& e ) {
+ delete conn;
+ throw;
+ }
return conn;
}
@@ -155,7 +161,13 @@ namespace mongo {
DBClientBase* DBConnectionPool::get(const ConnectionString& url, double socketTimeout) {
DBClientBase * c = _get( url.toString() , socketTimeout );
if ( c ) {
- onHandedOut( c );
+ try {
+ onHandedOut( c );
+ }
+ catch ( std::exception& e ) {
+ delete c;
+ throw;
+ }
return c;
}
@@ -169,7 +181,13 @@ namespace mongo {
DBClientBase* DBConnectionPool::get(const string& host, double socketTimeout) {
DBClientBase * c = _get( host , socketTimeout );
if ( c ) {
- onHandedOut( c );
+ try {
+ onHandedOut( c );
+ }
+ catch ( std::exception& e ) {
+ delete c;
+ throw;
+ }
return c;
}
diff --git a/s/shardconnection.cpp b/s/shardconnection.cpp
index 52ecabeae27..89b38396646 100644
--- a/s/shardconnection.cpp
+++ b/s/shardconnection.cpp
@@ -100,7 +100,13 @@ namespace mongo {
if ( s->avail ) {
DBClientBase* c = s->avail;
s->avail = 0;
- shardConnectionPool.onHandedOut( c );
+ try {
+ shardConnectionPool.onHandedOut( c );
+ }
+ catch ( std::exception& e ) {
+ delete c;
+ throw;
+ }
return c;
}