summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 01a4d0a)
raw | patch | inline | side by side (parent: 01a4d0a)
author | Florian Forster <octo@collectd.org> | |
Mon, 25 Mar 2013 06:28:36 +0000 (07:28 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Mon, 25 Mar 2013 06:33:22 +0000 (07:33 +0100) |
Apparently, if you call it with a structure allocated by mysql_init()
itself, it leaks memory. Thanks to Yves Mettier for pointing this out!
Fixes Github issue #274.
itself, it leaks memory. Thanks to Yves Mettier for pointing this out!
Fixes Github issue #274.
src/mysql.c | patch | blob | history |
diff --git a/src/mysql.c b/src/mysql.c
index 6f9efe356c923d6b7a390b0d8974059a6c5d6a3b..8b3cd210a9d48e49d854ec4b1d01ed3287ff9591 100644 (file)
--- a/src/mysql.c
+++ b/src/mysql.c
int slave_sql_running;
MYSQL *con;
- int state;
+ _Bool is_connected;
};
typedef struct mysql_database_s mysql_database_t; /* }}} */
static MYSQL *getconnection (mysql_database_t *db)
{
- if (db->state != 0)
+ if (db->is_connected)
{
- int err;
- if ((err = mysql_ping (db->con)) != 0)
- {
- WARNING ("mysql_ping failed for %s: %s",
- (db->instance != NULL)
- ? db->instance
- : "<legacy>",
- mysql_error (db->con));
- db->state = 0;
- }
- else
- {
- db->state = 1;
+ int status;
+
+ status = mysql_ping (db->con);
+ if (status == 0)
return (db->con);
- }
+
+ WARNING ("mysql plugin: Lost connection to instance \"%s\": %s",
+ (db->instance != NULL)
+ ? db->instance
+ : "<legacy>",
+ mysql_error (db->con));
}
+ db->is_connected = 0;
- if ((db->con = mysql_init (db->con)) == NULL)
+ if (db->con == NULL)
{
- ERROR ("mysql_init failed: %s", mysql_error (db->con));
- db->state = 0;
- return (NULL);
+ db->con = mysql_init (NULL);
+ if (db->con == NULL)
+ {
+ ERROR ("mysql plugin: mysql_init failed: %s",
+ mysql_error (db->con));
+ return (NULL);
+ }
}
if (mysql_real_connect (db->con, db->host, db->user, db->pass,
(db->database != NULL) ? db->database : "<none>",
(db->host != NULL) ? db->host : "localhost",
mysql_error (db->con));
- db->state = 0;
return (NULL);
}
- else
- {
- INFO ("mysql plugin: Successfully connected to database %s "
- "at server %s (server version: %s, protocol version: %d)",
- (db->database != NULL) ? db->database : "<none>",
- mysql_get_host_info (db->con),
- mysql_get_server_info (db->con),
- mysql_get_proto_info (db->con));
- db->state = 1;
- return (db->con);
- }
+
+ INFO ("mysql plugin: Successfully connected to database %s "
+ "at server %s (server version: %s, protocol version: %d)",
+ (db->database != NULL) ? db->database : "<none>",
+ mysql_get_host_info (db->con),
+ mysql_get_server_info (db->con),
+ mysql_get_proto_info (db->con));
+
+ db->is_connected = 1;
+ return (db->con);
} /* static MYSQL *getconnection (mysql_database_t *db) */
static void set_host (mysql_database_t *db, char *buf, size_t buflen)