about summary refs log tree commit diff
path: root/library/std/src/os
diff options
context:
space:
mode:
authorThe 8472 <git@infinite-source.de>2024-04-21 17:19:15 +0200
committerThe 8472 <git@infinite-source.de>2024-04-28 01:44:25 +0200
commit1ba00d9cb2fcfef464b6a188fa3a7543c66eecaa (patch)
tree2626b8a704fa0f5eaaccda41cd9950da8ea3b6f4 /library/std/src/os
parent25babe9a79a2c5d35211e0d6bad348637ef2a246 (diff)
put FD validity behind late debug_asserts checking
uses the same machinery as assert_unsafe_precondition
Diffstat (limited to 'library/std/src/os')
-rw-r--r--library/std/src/os/fd/owned.rs14
1 files changed, 3 insertions, 11 deletions
diff --git a/library/std/src/os/fd/owned.rs b/library/std/src/os/fd/owned.rs
index 8c421540af4..8c7fc4cb2e4 100644
--- a/library/std/src/os/fd/owned.rs
+++ b/library/std/src/os/fd/owned.rs
@@ -177,17 +177,9 @@ impl Drop for OwnedFd {
             // opened after we closed ours.
             #[cfg(not(target_os = "hermit"))]
             {
-                use crate::sys::os::errno;
-                // ideally this would use assert_unsafe_precondition!, but that's only in core
-                if cfg!(debug_assertions) {
-                    // close() can bubble up error codes from FUSE which can send semantically
-                    // inappropriate error codes including EBADF.
-                    // So we check file flags instead which live on the file descriptor and not the underlying file.
-                    // The downside is that it costs an extra syscall, so we only do it for debug.
-                    if libc::fcntl(self.fd, libc::F_GETFD) == -1 && errno() == libc::EBADF {
-                        rtabort!("IO Safety violation: owned file descriptor already closed");
-                    }
-                }
+                #[cfg(unix)]
+                crate::sys::fs::debug_assert_fd_is_open(self.fd);
+
                 let _ = libc::close(self.fd);
             }
             #[cfg(target_os = "hermit")]