Skip to content

Commit 038c9bb

Browse files
committed
Save errno across LWLockRelease() calls
Fixup for "Drop slot's LWLock before returning from SaveSlotToPath()" Reported-by: Michael Paquier <michael@paquier.xyz>
1 parent 44c763f commit 038c9bb

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/backend/replication/slot.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,9 +1254,13 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
12541254
/*
12551255
* If not an ERROR, then release the lock before returning. In case
12561256
* of an ERROR, the error recovery path automatically releases the
1257-
* lock, but no harm in explicitly releasing even in that case.
1257+
* lock, but no harm in explicitly releasing even in that case. Note
1258+
* that LWLockRelease() could affect errno.
12581259
*/
1260+
int save_errno = errno;
1261+
12591262
LWLockRelease(&slot->io_in_progress_lock);
1263+
errno = save_errno;
12601264
ereport(elevel,
12611265
(errcode_for_file_access(),
12621266
errmsg("could not create file \"%s\": %m",
@@ -1323,7 +1327,10 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
13231327
/* rename to permanent file, fsync file and directory */
13241328
if (rename(tmppath, path) != 0)
13251329
{
1330+
int save_errno = errno;
1331+
13261332
LWLockRelease(&slot->io_in_progress_lock);
1333+
errno = save_errno;
13271334
ereport(elevel,
13281335
(errcode_for_file_access(),
13291336
errmsg("could not rename file \"%s\" to \"%s\": %m",

0 commit comments

Comments
 (0)