From fdd5a104781dd72dd0004dbf152e452e31c3d49f Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Thu, 7 May 2015 11:42:14 +0300 Subject: [PATCH] Fixed a memory leak in all the monitors when a failed mysql_ping to the database caused a reinitialization of MYSQL* connection. --- server/modules/monitor/galera_mon.c | 2 ++ server/modules/monitor/mm_mon.c | 3 ++- server/modules/monitor/mysql_mon.c | 3 ++- server/modules/monitor/ndbcluster_mon.c | 2 ++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/server/modules/monitor/galera_mon.c b/server/modules/monitor/galera_mon.c index ec9e46a61..e38b402d7 100644 --- a/server/modules/monitor/galera_mon.c +++ b/server/modules/monitor/galera_mon.c @@ -377,6 +377,8 @@ char *server_string; int read_timeout = handle->read_timeout; int write_timeout = handle->write_timeout; + if(database->con) + mysql_close(database->con); database->con = mysql_init(NULL); rc = mysql_options(database->con, MYSQL_OPT_CONNECT_TIMEOUT, (void *)&connect_timeout); diff --git a/server/modules/monitor/mm_mon.c b/server/modules/monitor/mm_mon.c index 60acea825..bddb82db9 100644 --- a/server/modules/monitor/mm_mon.c +++ b/server/modules/monitor/mm_mon.c @@ -360,7 +360,8 @@ char *server_string; char *dpwd = decryptPassword(passwd); int rc; int read_timeout = 1; - + if(database->con) + mysql_close(database->con); database->con = mysql_init(NULL); rc = mysql_options(database->con, MYSQL_OPT_READ_TIMEOUT, (void *)&read_timeout); diff --git a/server/modules/monitor/mysql_mon.c b/server/modules/monitor/mysql_mon.c index d9e6d1d5d..2251e1d8d 100644 --- a/server/modules/monitor/mysql_mon.c +++ b/server/modules/monitor/mysql_mon.c @@ -401,7 +401,8 @@ char *server_string; int connect_timeout = handle->connect_timeout; int read_timeout = handle->read_timeout; int write_timeout = handle->write_timeout; - + if(database->con) + mysql_close(database->con); database->con = mysql_init(NULL); rc = mysql_options(database->con, MYSQL_OPT_CONNECT_TIMEOUT, (void *)&connect_timeout); diff --git a/server/modules/monitor/ndbcluster_mon.c b/server/modules/monitor/ndbcluster_mon.c index 8f7d00964..76a05fd03 100644 --- a/server/modules/monitor/ndbcluster_mon.c +++ b/server/modules/monitor/ndbcluster_mon.c @@ -338,6 +338,8 @@ char *server_string; int read_timeout = handle->read_timeout; int write_timeout = handle->write_timeout; + if(database->con) + mysql_close(database->con); database->con = mysql_init(NULL); rc = mysql_options(database->con, MYSQL_OPT_CONNECT_TIMEOUT, (void *)&connect_timeout);