mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-23 07:06:30 +00:00
fix: now CloseConnections() is much more safe
This commit is contained in:
23
repmgrd.c
23
repmgrd.c
@@ -147,14 +147,21 @@ static void setup_event_handlers(void);
|
||||
static void do_daemonize();
|
||||
static void check_and_create_pid_file(const char *pid_file);
|
||||
|
||||
#define CloseConnections() \
|
||||
if (PQisBusy(primaryConn) == 1) \
|
||||
(void) CancelQuery(primaryConn, local_options.master_response_timeout); \
|
||||
if (myLocalConn != NULL) \
|
||||
PQfinish(myLocalConn); \
|
||||
if (primaryConn != NULL && primaryConn != myLocalConn) \
|
||||
static void
|
||||
CloseConnections() {
|
||||
if (primaryConn != NULL && PQisBusy(primaryConn) == 1)
|
||||
CancelQuery(primaryConn, local_options.master_response_timeout);
|
||||
|
||||
if (myLocalConn != NULL)
|
||||
PQfinish(myLocalConn);
|
||||
|
||||
if (primaryConn != NULL && primaryConn != myLocalConn)
|
||||
PQfinish(primaryConn);
|
||||
|
||||
primaryConn = NULL;
|
||||
myLocalConn = NULL;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
@@ -431,10 +438,6 @@ main(int argc, char **argv)
|
||||
|
||||
} while (true);
|
||||
|
||||
/* Prevent a double-free */
|
||||
if (primaryConn == myLocalConn)
|
||||
myLocalConn = NULL;
|
||||
|
||||
/* close the connection to the database and cleanup */
|
||||
CloseConnections();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user