From c983fdf83c997a8ee799855c56d14d1791e93fbd Mon Sep 17 00:00:00 2001 From: Carlo Ascani Date: Tue, 26 Jul 2011 18:22:06 -0500 Subject: [PATCH] Fix a possible double free that would cause a segfault in checkNodeConfiguration() --- dbutils.c | 6 ++---- repmgrd.c | 5 ++++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/dbutils.c b/dbutils.c index 8e64699a..668dd0dd 100644 --- a/dbutils.c +++ b/dbutils.c @@ -101,7 +101,7 @@ bool is_witness(PGconn *conn, char *schema, char *cluster, int node_id) { PGresult *res; - bool result; + bool result = false; char sqlquery[QUERY_STR_LEN]; sqlquery_snprintf(sqlquery, "SELECT witness from %s.repl_nodes where cluster = '%s' and id = %d", @@ -115,9 +115,7 @@ is_witness(PGconn *conn, char *schema, char *cluster, int node_id) exit(ERR_DB_QUERY); } - if (strcmp(PQgetvalue(res, 0, 0), "f") == 0) - result = false; - else + if (PQntuples(res) == 1 && strcmp(PQgetvalue(res, 0, 0), "t") == 0) result = true; PQclear(res); diff --git a/repmgrd.c b/repmgrd.c index 60456bb0..92f3f1b5 100644 --- a/repmgrd.c +++ b/repmgrd.c @@ -871,7 +871,10 @@ checkNodeConfiguration(char *conninfo) exit(ERR_BAD_CONFIG); } } - PQclear(res); + else + { + PQclear(res); + } }