From 309bb92d95e9aac917bcd9d2ef28e5964666eb94 Mon Sep 17 00:00:00 2001 From: Dan Farina Date: Fri, 10 Dec 2010 12:51:42 -0800 Subject: [PATCH] Prevent a double-free This can occur because prior to this, there is a code path that looks like this: primaryConn = myLocalConn CloseConnections will subsequently try to free both with PQFinish. I'm not sure if this is the right fix -- it's more of hack -- without more information about design intention. One reasonable alternative would be to have CloseConnections perform this check itself. As-is I am pretty sure that this fix leaves a signal-race (when CloseConnections is called, without the check, in the interrupt handler) unfixed. Signed-off-by: Dan Farina Signed-off-by: Peter van Hardenberg --- repmgrd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/repmgrd.c b/repmgrd.c index c82ddd73..3798171c 100644 --- a/repmgrd.c +++ b/repmgrd.c @@ -180,6 +180,10 @@ main(int argc, char **argv) MonitorCheck(); } + /* Prevent a double-free */ + if (primaryConn == myLocalConn) + myLocalConn = NULL; + /* close the connection to the database and cleanup */ CloseConnections();