From 614c252733846a3a334b342a40e8a2234e20fb00 Mon Sep 17 00:00:00 2001 From: Dhrupad Bhardwaj Date: Thu, 1 Mar 2018 18:45:14 -0500 Subject: [PATCH] Properly cleanup dropped MySQL connections. --- src/mysql.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/mysql.c b/src/mysql.c index 7fe6d764..448f7cba 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -270,12 +270,16 @@ static MYSQL *getconnection(mysql_database_t *db) { } db->is_connected = 0; + /* Close the old connection before initializing a new one. */ + if (db->con != NULL) { + mysql_close(db->con); + db->con = NULL; + } + + db->con = mysql_init(NULL); if (db->con == NULL) { - db->con = mysql_init(NULL); - if (db->con == NULL) { - ERROR("mysql plugin: mysql_init failed: %s", mysql_error(db->con)); - return NULL; - } + ERROR("mysql plugin: mysql_init failed: %s", mysql_error(db->con)); + return NULL; } /* Configure TCP connect timeout (default: 0) */ -- 2.11.0