From: Dhrupad Bhardwaj Date: Thu, 1 Mar 2018 23:45:14 +0000 (-0500) Subject: Properly cleanup dropped MySQL connections. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=614c252733846a3a334b342a40e8a2234e20fb00;p=collectd.git Properly cleanup dropped MySQL connections. --- 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) */