From c9710b3f55590b20401a4e6b4a6d3fb3c304cfec Mon Sep 17 00:00:00 2001 From: Filip Salomonsson Date: Fri, 16 Jan 2015 22:41:03 +0100 Subject: [PATCH] Close and delete the socket if connect() fails --- lib/Connection.cpp | 3 +++ tests/tests.py | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Connection.cpp b/lib/Connection.cpp index fcacef6..28f72db 100644 --- a/lib/Connection.cpp +++ b/lib/Connection.cpp @@ -480,6 +480,9 @@ bool Connection::connect(const char *_host, int _port, const char *_username, co if (!connectSocket()) { m_dbgMethodProgress --; + m_capi.closeSocket(m_sockInst); + m_capi.deleteSocket(m_sockInst); + m_sockInst = NULL; return false; } diff --git a/tests/tests.py b/tests/tests.py index d969578..7cb95ec 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -149,7 +149,7 @@ def testConnectTimeout(self): try: res = cnn.query("select * from kaka"); assert False, "Expected exception" - except(socket.error): + except(RuntimeError): pass cnn.close() @@ -161,6 +161,7 @@ def testConnectFails(self): assert False, "Expected exception" except(socket.error): pass + self.assertFalse(cnn.is_connected()) cnn.close() def testConnectDNSFails(self):