mdbx: устранение риска потери/перезаписи errno при неожиданных ошибках в close().

This commit is contained in:
Леонид Юрьев (Leonid Yuriev) 2025-01-12 02:16:44 +03:00
parent b75e16f4f8
commit 92a49c7c8c

View File

@ -1343,6 +1343,7 @@ MDBX_INTERNAL int osal_openfile(const enum osal_openfile_purpose purpose, const
assert(stub_fd2 == -1); assert(stub_fd2 == -1);
*fd = dup(stub_fd2 = *fd); *fd = dup(stub_fd2 = *fd);
} }
const int err = errno;
if (stub_fd0 != -1) if (stub_fd0 != -1)
close(stub_fd0); close(stub_fd0);
if (stub_fd1 != -1) if (stub_fd1 != -1)
@ -1361,7 +1362,7 @@ MDBX_INTERNAL int osal_openfile(const enum osal_openfile_purpose purpose, const
#endif /* STDIN_FILENO == 0 && STDERR_FILENO == 2 */ #endif /* STDIN_FILENO == 0 && STDERR_FILENO == 2 */
if (*fd < 0) if (*fd < 0)
return errno; return err;
#if defined(FD_CLOEXEC) && !defined(O_CLOEXEC) #if defined(FD_CLOEXEC) && !defined(O_CLOEXEC)
const int fd_flags = fcntl(*fd, F_GETFD); const int fd_flags = fcntl(*fd, F_GETFD);