X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fmysql.c;fp=src%2Fmysql.c;h=448f7cbace4538c21d2195d6235a3787207666de;hp=7fe6d76470724861304a0a601d24c1993d19da2b;hb=614c252733846a3a334b342a40e8a2234e20fb00;hpb=b77e13de9c2d63bda11c858b0dd2d1abb20600c4 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) */