From 3c36ed18ba1928f9a6fe05509eec3ed20839c57d Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 4 Sep 2023 15:35:08 +0200 Subject: [PATCH] free mysql->connector_fd correctly in the internal client it's not an ssl option, so shouldn't be in mysql_ssl_free(), which frees ssl options, and only unless CLIENT_REMEMBER_OPTIONS is set. mysql->connector_fd must be freed when mysql->net.vio is closed and fd becomes no longer valid --- sql-common/client.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sql-common/client.c b/sql-common/client.c index ddc5f1a4475..5b03c903153 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -723,6 +723,12 @@ void end_server(MYSQL *mysql) DBUG_ENTER("end_server"); if (mysql->net.vio != 0) { + struct st_VioSSLFd *ssl_fd= (struct st_VioSSLFd*) mysql->connector_fd; + if (ssl_fd) + SSL_CTX_free(ssl_fd->ssl_context); + my_free(ssl_fd); + mysql->connector_fd = 0; + DBUG_PRINT("info",("Net: %s", vio_description(mysql->net.vio))); #ifdef MYSQL_SERVER slave_io_thread_detach_vio(); @@ -1509,7 +1515,6 @@ mysql_ssl_set(MYSQL *mysql __attribute__((unused)) , static void mysql_ssl_free(MYSQL *mysql __attribute__((unused))) { - struct st_VioSSLFd *ssl_fd= (struct st_VioSSLFd*) mysql->connector_fd; DBUG_ENTER("mysql_ssl_free"); my_free(mysql->options.ssl_key); @@ -1522,9 +1527,6 @@ mysql_ssl_free(MYSQL *mysql __attribute__((unused))) my_free(mysql->options.extension->ssl_crl); my_free(mysql->options.extension->ssl_crlpath); } - if (ssl_fd) - SSL_CTX_free(ssl_fd->ssl_context); - my_free(mysql->connector_fd); mysql->options.ssl_key = 0; mysql->options.ssl_cert = 0; mysql->options.ssl_ca = 0; @@ -1536,7 +1538,6 @@ mysql_ssl_free(MYSQL *mysql __attribute__((unused))) mysql->options.extension->ssl_crlpath = 0; } mysql->options.use_ssl = FALSE; - mysql->connector_fd = 0; DBUG_VOID_RETURN; }