Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 250041a

Browse files
committed
Save errno across LWLockRelease() calls
Fixup for "Drop slot's LWLock before returning from SaveSlotToPath()" Reported-by: Michael Paquier <[email protected]>
1 parent 0912fb3 commit 250041a

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
@@ -1260,9 +1260,13 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
12601260
/*
12611261
* If not an ERROR, then release the lock before returning. In case
12621262
* of an ERROR, the error recovery path automatically releases the
1263-
* lock, but no harm in explicitly releasing even in that case.
1263+
* lock, but no harm in explicitly releasing even in that case. Note
1264+
* that LWLockRelease() could affect errno.
12641265
*/
1266+
int save_errno = errno;
1267+
12651268
LWLockRelease(&slot->io_in_progress_lock);
1269+
errno = save_errno;
12661270
ereport(elevel,
12671271
(errcode_for_file_access(),
12681272
errmsg("could not create file \"%s\": %m",
@@ -1329,7 +1333,10 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
13291333
/* rename to permanent file, fsync file and directory */
13301334
if (rename(tmppath, path) != 0)
13311335
{
1336+
int save_errno = errno;
1337+
13321338
LWLockRelease(&slot->io_in_progress_lock);
1339+
errno = save_errno;
13331340
ereport(elevel,
13341341
(errcode_for_file_access(),
13351342
errmsg("could not rename file \"%s\" to \"%s\": %m",

0 commit comments

Comments
 (0)