@@ -1254,9 +1254,13 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
1254
1254
/*
1255
1255
* If not an ERROR, then release the lock before returning. In case
1256
1256
* 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.
1258
1259
*/
1260
+ int save_errno = errno ;
1261
+
1259
1262
LWLockRelease (& slot -> io_in_progress_lock );
1263
+ errno = save_errno ;
1260
1264
ereport (elevel ,
1261
1265
(errcode_for_file_access (),
1262
1266
errmsg ("could not create file \"%s\": %m" ,
@@ -1323,7 +1327,10 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
1323
1327
/* rename to permanent file, fsync file and directory */
1324
1328
if (rename (tmppath ,path )!= 0 )
1325
1329
{
1330
+ int save_errno = errno ;
1331
+
1326
1332
LWLockRelease (& slot -> io_in_progress_lock );
1333
+ errno = save_errno ;
1327
1334
ereport (elevel ,
1328
1335
(errcode_for_file_access (),
1329
1336
errmsg ("could not rename file \"%s\" to \"%s\": %m" ,