More robust KeepLogSeg() coding
authorAndres Freund <andres@anarazel.de>
Wed, 29 Jan 2014 12:56:55 +0000 (13:56 +0100)
committerAndres Freund <andres@anarazel.de>
Wed, 29 Jan 2014 12:56:55 +0000 (13:56 +0100)
src/backend/access/transam/xlog.c

index a77ff5fe5e9aade1f949fecfa8091f5718bb8258..ee1c0a31130da42a70e61ef9c241d470935f2833 100644 (file)
@@ -9000,7 +9000,7 @@ CreateRestartPoint(int flags)
 static void
 KeepLogSeg(XLogRecPtr recptr, XLogSegNo *logSegNo)
 {
-       XLogSegNo       segno, slotSegNo;
+       XLogSegNo       segno;
        XLogRecPtr      keep;
 
        XLByteToSeg(recptr, segno);
@@ -9019,9 +9019,13 @@ KeepLogSeg(XLogRecPtr recptr, XLogSegNo *logSegNo)
        /* then check whether slots limit removal further */
        if (max_replication_slots > 0 && keep != InvalidXLogRecPtr)
        {
-               XLByteToPrevSeg(keep, slotSegNo);
+               XLogRecPtr slotSegNo;
+
+               XLByteToSeg(keep, slotSegNo);
 
-               if (slotSegNo < segno)
+               if (slotSegNo <= 0)
+                       segno = 1;
+               else if (slotSegNo < segno)
                        segno = slotSegNo;
        }