Properly initialize write, flush and replay locations in walsender slots
authorMagnus Hagander <magnus@hagander.net>
Sun, 13 Dec 2015 15:40:37 +0000 (16:40 +0100)
committerMagnus Hagander <magnus@hagander.net>
Sun, 13 Dec 2015 15:44:04 +0000 (16:44 +0100)
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

index 50cb0048d6bb81477bb5c62c6c90006f0aed1714..9b455eef58579269a45ade70e721cfd6d89ba2f6 100644 (file)
@@ -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);