From c16ab3c889d42fe969da28235b505ec96be34160 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Tue, 21 Jun 2016 17:30:22 +0900 Subject: [PATCH] Fix handling of global PGconn variables in repmgrd Don't call PQfinish before calling terminate(), elsewhere always set to NULL after calling PQfinish(). This fixes GitHub #182. --- repmgrd.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/repmgrd.c b/repmgrd.c index d4db87fe..06a99c18 100644 --- a/repmgrd.c +++ b/repmgrd.c @@ -1195,7 +1195,6 @@ do_master_failover(void) { log_err(_("unable to retrieve node records: %s\n"), PQerrorMessage(my_local_conn)); PQclear(res); - PQfinish(my_local_conn); terminate(ERR_DB_QUERY); } @@ -1569,12 +1568,12 @@ do_master_failover(void) log_notice(_("Original master reappeared before this standby was promoted - no action taken\n")); PQfinish(master_conn); + master_conn = NULL; + /* no failover occurred but we'll want to restart connections */ failover_done = true; return; } - - PQfinish(my_local_conn); } log_err(_("promote command failed. You could check and try it manually.\n")); @@ -2446,6 +2445,8 @@ get_node_info(PGconn *conn, char *cluster, int node_id) errmsg.data); PQfinish(conn); + conn = NULL; + terminate(ERR_DB_QUERY); }