Skip to content

Commit 1cb2b86

Browse files
committed
Bug #27434254: MASTER : MEMORY LEAK WHILE CONNECTION WITH WRONG SSL-CA ATTEMPTED.
In case of error thrown from connect() the newly created TLS object was not deleted. Fixed by using unique_ptr.
1 parent f71c3b6 commit 1cb2b86

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

cdk/core/session.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
namespace cdk {
3737

38+
using std::unique_ptr;
39+
3840
/*
3941
A class that creates a session from given data source.
4042
@@ -261,14 +263,20 @@ Session_builder::tls_connect(Socket_base &connection, const TLS::Options &option
261263
if (!prc.m_tls)
262264
return NULL;
263265

264-
// Capabilites OK, create TLS connection now.
266+
/*
267+
Capabilites OK, create TLS connection now.
268+
269+
Note: The TLS object is protected by unique_ptr<> for the case that
270+
connection attempt below throws an error - in that case the newly created
271+
object should be deleted.
272+
*/
265273

266-
TLS *tls_conn = new TLS(&connection, options);
274+
unique_ptr<TLS> tls_conn(new TLS(&connection, options));
267275

268276
// TODO: attempt failover if TLS-layer reports network error?
269277
tls_conn->connect();
270278

271-
return tls_conn;
279+
return tls_conn.release();
272280
}
273281

274282
#endif

0 commit comments

Comments
 (0)