From 5421f5b0e63abfe18b6f09d75c44697cdac699f3 Mon Sep 17 00:00:00 2001 From: Kyotaro Horiguchi Date: Thu, 14 May 2020 13:37:50 +0900 Subject: [PATCH] Don't check uninitialized xlog reader state WanSndErrorCleanup may be called before initialization of the variable xlogreader and crashes in that case. Let the function not to examine the xlogreader state if not yet initialized. --- src/backend/replication/walsender.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index 3367aa98f8..661fa12a94 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -136,7 +136,7 @@ bool wake_wal_senders = false; * routines. */ static XLogReaderState fake_xlogreader; -static XLogReaderState *xlogreader; +static XLogReaderState *xlogreader = NULL; /* * These variables keep track of the state of the timeline we're currently @@ -315,7 +315,7 @@ WalSndErrorCleanup(void) ConditionVariableCancelSleep(); pgstat_report_wait_end(); - if (xlogreader->seg.ws_file >= 0) + if (xlogreader != NULL && xlogreader->seg.ws_file >= 0) wal_segment_close(xlogreader); if (MyReplicationSlot != NULL) -- 2.18.2