From 31ea9f945d2acfa8e0dec18df8ae7094d7ca62b0 Mon Sep 17 00:00:00 2001
From: unknown <gluh@eagle.intranet.mysql.r18.ru>
Date: Mon, 21 Nov 2005 16:09:26 +0400
Subject: [PATCH] Fix for bug#14780 memory leak for mysql 4.1.14 with openssl
 enabled

---
 sql-common/client.c |  6 +++++-
 vio/vio.c           |  2 +-
 vio/vio_priv.h      |  1 -
 vio/viossl.c        | 19 -------------------
 4 files changed, 6 insertions(+), 22 deletions(-)

diff --git a/sql-common/client.c b/sql-common/client.c
index 3979b9304f7..3a598832253 100644
--- a/sql-common/client.c
+++ b/sql-common/client.c
@@ -1487,11 +1487,15 @@ mysql_ssl_set(MYSQL *mysql __attribute__((unused)) ,
 static void
 mysql_ssl_free(MYSQL *mysql __attribute__((unused)))
 {
+  struct st_VioSSLConnectorFd *st= 
+    (struct st_VioSSLConnectorFd*) mysql->connector_fd;
   my_free(mysql->options.ssl_key, MYF(MY_ALLOW_ZERO_PTR));
   my_free(mysql->options.ssl_cert, MYF(MY_ALLOW_ZERO_PTR));
   my_free(mysql->options.ssl_ca, MYF(MY_ALLOW_ZERO_PTR));
   my_free(mysql->options.ssl_capath, MYF(MY_ALLOW_ZERO_PTR));
-  my_free(mysql->options.ssl_cipher, MYF(MY_ALLOW_ZERO_PTR));
+  my_free(mysql->options.ssl_cipher, MYF(MY_ALLOW_ZERO_PTR));  
+  if (st)
+    SSL_CTX_free(st->ssl_context);
   my_free(mysql->connector_fd,MYF(MY_ALLOW_ZERO_PTR));
   mysql->options.ssl_key = 0;
   mysql->options.ssl_cert = 0;
diff --git a/vio/vio.c b/vio/vio.c
index 427c52e29d3..6174acd7024 100644
--- a/vio/vio.c
+++ b/vio/vio.c
@@ -83,7 +83,7 @@ void vio_reset(Vio* vio, enum enum_vio_type type,
 #ifdef HAVE_OPENSSL 
   if (type == VIO_TYPE_SSL)
   {
-    vio->viodelete	=vio_ssl_delete;
+    vio->viodelete	=vio_delete;
     vio->vioerrno	=vio_ssl_errno;
     vio->read		=vio_ssl_read;
     vio->write		=vio_ssl_write;
diff --git a/vio/vio_priv.h b/vio/vio_priv.h
index c1c78cc6efa..eb495025ddd 100644
--- a/vio/vio_priv.h
+++ b/vio/vio_priv.h
@@ -28,7 +28,6 @@ void	vio_ignore_timeout(Vio *vio, uint which, uint timeout);
 #ifdef HAVE_OPENSSL
 #include "my_net.h"			/* needed because of struct in_addr */
 
-void	vio_ssl_delete(Vio* vio);
 int	vio_ssl_read(Vio *vio,gptr buf,	int size);
 int	vio_ssl_write(Vio *vio,const gptr buf,int size);
 void	vio_ssl_timeout(Vio *vio, uint which, uint timeout);
diff --git a/vio/viossl.c b/vio/viossl.c
index a3a2e7190bd..62145fe5006 100644
--- a/vio/viossl.c
+++ b/vio/viossl.c
@@ -69,25 +69,6 @@ report_errors()
   DBUG_VOID_RETURN;
 }
 
-/*
-  Delete a vio object
-
-  SYNPOSIS
-    vio_ssl_delete()
-    vio			Vio object.  May be 0.
-*/
-
-
-void vio_ssl_delete(Vio * vio)
-{
-  if (vio)
-  {
-    if (vio->type != VIO_CLOSED)
-      vio_close(vio);
-    my_free((gptr) vio,MYF(0));
-  }
-}
-
 
 int vio_ssl_errno(Vio *vio __attribute__((unused)))
 {