From 0ba1e628110dbf2cea3ee723f5276337228223a8 Mon Sep 17 00:00:00 2001 From: Matej Kenda Date: Wed, 3 Feb 2016 21:23:18 +0100 Subject: [PATCH] MongoDB::PooledConnection: Prevent unwanted release by disabling copy semantics. Enabled move semantics for C++11. --- .../Poco/MongoDB/PoolableConnectionFactory.h | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/MongoDB/include/Poco/MongoDB/PoolableConnectionFactory.h b/MongoDB/include/Poco/MongoDB/PoolableConnectionFactory.h index b2e3c492f..e077f10bf 100644 --- a/MongoDB/include/Poco/MongoDB/PoolableConnectionFactory.h +++ b/MongoDB/include/Poco/MongoDB/PoolableConnectionFactory.h @@ -86,7 +86,10 @@ public: { try { - _pool.returnObject(_connection); + if (_connection) + { + _pool.returnObject(_connection); + } } catch (...) { @@ -99,7 +102,24 @@ public: return _connection; } +#if defined(POCO_ENABLE_CPP11) + // Disable copy to prevent unwanted release of resources: C++11 way + PooledConnection(const PooledConnection&) = delete; + PooledConnection& operator=(const PooledConnection&) = delete; + + // Enable move semantics + PooledConnection(PooledConnection&& other) = default; + PooledConnection& operator=(PooledConnection&&) = default; +#endif + private: + +#if ! defined(POCO_ENABLE_CPP11) + // Disable copy to prevent unwanted release of resources: pre C++11 way + PooledConnection(const PooledConnection&); + PooledConnection& operator=(const PooledConnection&); +#endif + Poco::ObjectPool& _pool; Connection::Ptr _connection; };