@@ -1260,9 +1260,13 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
1260
1260
/*
1261
1261
* If not an ERROR, then release the lock before returning. In case
1262
1262
* 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.
1264
1265
*/
1266
+ int save_errno = errno ;
1267
+
1265
1268
LWLockRelease (& slot -> io_in_progress_lock );
1269
+ errno = save_errno ;
1266
1270
ereport (elevel ,
1267
1271
(errcode_for_file_access (),
1268
1272
errmsg ("could not create file \"%s\": %m" ,
@@ -1329,7 +1333,10 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
1329
1333
/* rename to permanent file, fsync file and directory */
1330
1334
if (rename (tmppath ,path )!= 0 )
1331
1335
{
1336
+ int save_errno = errno ;
1337
+
1332
1338
LWLockRelease (& slot -> io_in_progress_lock );
1339
+ errno = save_errno ;
1333
1340
ereport (elevel ,
1334
1341
(errcode_for_file_access (),
1335
1342
errmsg ("could not rename file \"%s\" to \"%s\": %m" ,