@@ -1259,9 +1259,13 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
12591259 /*
12601260 * If not an ERROR, then release the lock before returning. In case
12611261 * of an ERROR, the error recovery path automatically releases the
1262- * lock, but no harm in explicitly releasing even in that case.
1262+ * lock, but no harm in explicitly releasing even in that case. Note
1263+ * that LWLockRelease() could affect errno.
12631264 */
1265+ int save_errno = errno ;
1266+
12641267 LWLockRelease (& slot -> io_in_progress_lock );
1268+ errno = save_errno ;
12651269 ereport (elevel ,
12661270 (errcode_for_file_access (),
12671271 errmsg ("could not create file \"%s\": %m" ,
@@ -1325,7 +1329,10 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
13251329
13261330 if (CloseTransientFile (fd ) != 0 )
13271331 {
1332+ int save_errno = errno ;
1333+
13281334 LWLockRelease (& slot -> io_in_progress_lock );
1335+ errno = save_errno ;
13291336 ereport (elevel ,
13301337 (errcode_for_file_access (),
13311338 errmsg ("could not close file \"%s\": %m" ,
@@ -1336,7 +1343,10 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
13361343 /* rename to permanent file, fsync file and directory */
13371344 if (rename (tmppath , path ) != 0 )
13381345 {
1346+ int save_errno = errno ;
1347+
13391348 LWLockRelease (& slot -> io_in_progress_lock );
1349+ errno = save_errno ;
13401350 ereport (elevel ,
13411351 (errcode_for_file_access (),
13421352 errmsg ("could not rename file \"%s\" to \"%s\": %m" ,
0 commit comments