about summary refs log tree commit diff
path: root/library/std/src/sys
diff options
context:
space:
mode:
authorGeorgii Rylov <g0dj4n@gmail.com>2023-08-10 14:06:41 +0100
committerGeorgii Rylov <g0dj4n@gmail.com>2023-08-16 11:21:05 +0100
commit42a708083a59ece9599723f69536ddb6e987e6e4 (patch)
tree6f604eead98a3f133118709f3df40139e38f2a68 /library/std/src/sys
parent60713f4234c56e21f77e37c61dd731247d0b9429 (diff)
downloadrust-42a708083a59ece9599723f69536ddb6e987e6e4.tar.gz
rust-42a708083a59ece9599723f69536ddb6e987e6e4.zip
Fix a pthread_t handle leak #114610
Diffstat (limited to 'library/std/src/sys')
-rw-r--r--library/std/src/sys/wasi/thread.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/library/std/src/sys/wasi/thread.rs b/library/std/src/sys/wasi/thread.rs
index dbad425976a..99717613f57 100644
--- a/library/std/src/sys/wasi/thread.rs
+++ b/library/std/src/sys/wasi/thread.rs
@@ -47,6 +47,7 @@ cfg_if::cfg_if! {
                     stack_size: libc::size_t,
                 ) -> ffi::c_int;
                 pub fn pthread_attr_destroy(attr: *mut pthread_attr_t) -> ffi::c_int;
+                pub fn pthread_detach(thread: pthread_t) -> ffi::c_int;
             }
         }
 
@@ -178,6 +179,17 @@ impl Thread {
     }
 }
 
+cfg_if::cfg_if! {
+    if #[cfg(target_feature = "atomics")] {
+        impl Drop for Thread {
+            fn drop(&mut self) {
+                let ret = unsafe { libc::pthread_detach(self.id) };
+                debug_assert_eq!(ret, 0);
+            }
+        }
+    }
+}
+
 pub fn available_parallelism() -> io::Result<NonZeroUsize> {
     unsupported()
 }