From 263c19572bd4947b4cf977d61db11b74b1745570 Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Sun, 13 Dec 2015 16:40:37 +0100 Subject: [PATCH] Properly initialize write, flush and replay locations in walsender slots These would leak random xlog positions if a walsender used for backup would a walsender slot previously used by a replication walsender. In passing also fix a couple of cases where the xlog pointer is directly compared to zero instead of using XLogRecPtrIsInvalid, noted by Michael Paquier. --- src/backend/replication/walsender.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index 4a4643ef2f..c13567298c 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -1962,6 +1962,9 @@ InitWalSenderSlot(void) */ walsnd->pid = MyProcPid; walsnd->sentPtr = InvalidXLogRecPtr; + walsnd->write = InvalidXLogRecPtr; + walsnd->flush = InvalidXLogRecPtr; + walsnd->apply = InvalidXLogRecPtr; walsnd->state = WALSNDSTATE_STARTUP; walsnd->latch = &MyProc->procLatch; SpinLockRelease(&walsnd->mutex); @@ -2821,15 +2824,15 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS) values[1] = CStringGetTextDatum(WalSndGetStateString(state)); values[2] = LSNGetDatum(sentPtr); - if (write == 0) + if (XLogRecPtrIsInvalid(write)) nulls[3] = true; values[3] = LSNGetDatum(write); - if (flush == 0) + if (XLogRecPtrIsInvalid(flush)) nulls[4] = true; values[4] = LSNGetDatum(flush); - if (apply == 0) + if (XLogRecPtrIsInvalid(apply)) nulls[5] = true; values[5] = LSNGetDatum(apply); -- 2.40.0