@@ -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+
12591262LWLockRelease (& slot -> io_in_progress_lock );
1263+ errno = save_errno ;
12601264ereport (elevel ,
12611265(errcode_for_file_access (),
12621266errmsg ("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 */
13241328if (rename (tmppath ,path )!= 0 )
13251329{
1330+ int save_errno = errno ;
1331+
13261332LWLockRelease (& slot -> io_in_progress_lock );
1333+ errno = save_errno ;
13271334ereport (elevel ,
13281335(errcode_for_file_access (),
13291336errmsg ("could not rename file \"%s\" to \"%s\": %m" ,