From 01ba8bf8862a7dc2e53be7d31034f379b27be30a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Wed, 5 Dec 2018 13:33:39 +0200 Subject: [PATCH] MXS-2196: Fix freeing of resources on failed accept When an attempt to accept a client DCB fails, the session should only be deleted directly if the allocation of the client DCB fails. Otherwise the closing of the DCB triggers the session deletion. --- server/core/listener.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/server/core/listener.cc b/server/core/listener.cc index e116bf656..cfa81898f 100644 --- a/server/core/listener.cc +++ b/server/core/listener.cc @@ -864,15 +864,21 @@ DCB* Listener::accept_one_dcb() configure_network_socket(c_sock, client_conn.ss_family); mxs::Session* session = new(std::nothrow) mxs::Session(m_self); + + if (!session) + { + MXS_OOM(); + close(c_sock); + return NULL; + } + client_dcb = dcb_alloc(DCB::Role::CLIENT, session); - if (!session || !client_dcb) + if (!client_dcb) { - MXS_ERROR("Failed to create session objects for client connection."); + MXS_OOM(); close(c_sock); delete session; - dcb_close(client_dcb); - return NULL; } else { @@ -914,7 +920,6 @@ DCB* Listener::accept_one_dcb() && (client_dcb->authenticator_data = m_auth_func.create(m_auth_instance)) == NULL) { MXS_ERROR("Failed to create authenticator for client DCB"); - delete session; dcb_close(client_dcb); return NULL; } @@ -931,7 +936,6 @@ DCB* Listener::accept_one_dcb() // TODO: This is never used as the client connection is not up yet client_dcb->session->close_reason = SESSION_CLOSE_TOO_MANY_CONNECTIONS; - delete session; dcb_close(client_dcb); client_dcb = NULL; }