X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fpostgresql.c;h=a5bacf49b2a4fc8df8aeaabbbdb2c8b4e3e63e4b;hb=568420ac172981edccb8587cc9651952fe350365;hp=43f5af563af18e04d7a5478030565aa26055e93d;hpb=fe86778a8eea71062db899f9f7d6f7f79817067d;p=collectd.git diff --git a/src/postgresql.c b/src/postgresql.c index 43f5af56..a5bacf49 100644 --- a/src/postgresql.c +++ b/src/postgresql.c @@ -243,6 +243,7 @@ static c_psql_database_t *c_psql_database_new (const char *name) static void c_psql_database_delete (c_psql_database_t *db) { PQfinish (db->conn); + db->conn = NULL; sfree (db->queries); db->queries_num = 0; @@ -416,14 +417,17 @@ static int c_psql_exec_query (c_psql_database_t *db, int idx) } rows = PQntuples (res); - if (1 > rows) + if (1 > rows) { + PQclear (res); return 0; + } cols = PQnfields (res); if (query->cols_num != cols) { log_err ("SQL query returned wrong number of fields " "(expected: %i, got: %i)", query->cols_num, cols); log_info ("SQL query was: %s", query->query); + PQclear (res); return -1; } @@ -441,6 +445,7 @@ static int c_psql_exec_query (c_psql_database_t *db, int idx) submit_gauge (db, col.type, col.type_instance, value); } } + PQclear (res); return 0; } /* c_psql_exec_query */ @@ -545,6 +550,12 @@ static int c_psql_init (void) int j; + /* this will happen during reinitialization */ + if (NULL != db->conn) { + c_psql_check_connection (db); + continue; + } + status = ssnprintf (buf, buf_len, "dbname = '%s'", db->database); if (0 < status) { buf += status;