diff options
author | Eliot Horowitz <eliot@10gen.com> | 2011-11-20 02:29:13 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2011-11-21 01:01:33 -0500 |
commit | 163a0ede78d1dcbde86346248ff993db876f2a03 (patch) | |
tree | 57685f1a85755a5a476ae692669b017c25b14e7b /client | |
parent | 3a57f18f763ee0628badf8375dc41add957eaa67 (diff) | |
download | mongo-163a0ede78d1dcbde86346248ff993db876f2a03.tar.gz |
don't leak connections when onCreate or onHandOut hook fails SERVER-4331
Diffstat (limited to 'client')
-rw-r--r-- | client/connpool.cpp | 28 |
1 files changed, 23 insertions, 5 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; } |