From a1fb84990dc172f21f12a8fb79ab58876e81fe6b 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 50cb0048d6b..9b455eef585 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -1195,6 +1195,9 @@ InitWalSenderSlot(void) */ walsnd->pid = MyProcPid; walsnd->sentPtr = InvalidXLogRecPtr; + walsnd->write = InvalidXLogRecPtr; + walsnd->flush = InvalidXLogRecPtr; + walsnd->apply = InvalidXLogRecPtr; walsnd->state = WALSNDSTATE_STARTUP; SpinLockRelease(&walsnd->mutex); /* don't need the lock anymore */ @@ -1994,19 +1997,19 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS) (uint32) (sentPtr >> 32), (uint32) sentPtr); values[2] = CStringGetTextDatum(location); - if (write == 0) + if (XLogRecPtrIsInvalid(write)) nulls[3] = true; snprintf(location, sizeof(location), "%X/%X", (uint32) (write >> 32), (uint32) write); values[3] = CStringGetTextDatum(location); - if (flush == 0) + if (XLogRecPtrIsInvalid(flush)) nulls[4] = true; snprintf(location, sizeof(location), "%X/%X", (uint32) (flush >> 32), (uint32) flush); values[4] = CStringGetTextDatum(location); - if (apply == 0) + if (XLogRecPtrIsInvalid(apply)) nulls[5] = true; snprintf(location, sizeof(location), "%X/%X", (uint32) (apply >> 32), (uint32) apply);