about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2023-08-23 17:46:33 +0200
committerGitHub <noreply@github.com>2023-08-23 17:46:33 +0200
commit128ff0897b8c412af8963fef04a120fd266fc985 (patch)
tree83160a87ca9fa43f3cdda486c5a057aacefb473b
parent97fff1f2ed01f6f7c0c204530b693c74d88c2105 (diff)
parent9b00e5f06f51703c5294af602959d3f92c095aa7 (diff)
downloadrust-128ff0897b8c412af8963fef04a120fd266fc985.tar.gz
rust-128ff0897b8c412af8963fef04a120fd266fc985.zip
Rollup merge of #114696 - g0djan:godjan/fix_114610, r=Mark-Simulacrum
Fix a pthread_t handle leak #114610

https://github.com/rust-lang/rust/issues/114610

Ran the tests as described in https://github.com/rust-lang/rust/blob/master/src/doc/rustc/src/platform-support/wasm32-wasi-preview1-threads.md?plain=1#L125
-rw-r--r--library/std/src/sys/wasi/thread.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/library/std/src/sys/wasi/thread.rs b/library/std/src/sys/wasi/thread.rs
index dbad425976a..a0eefa8811a 100644
--- a/library/std/src/sys/wasi/thread.rs
+++ b/library/std/src/sys/wasi/thread.rs
@@ -47,12 +47,20 @@ 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;
             }
         }
 
         pub struct Thread {
             id: libc::pthread_t,
         }
+
+        impl Drop for Thread {
+            fn drop(&mut self) {
+                let ret = unsafe { libc::pthread_detach(self.id) };
+                debug_assert_eq!(ret, 0);
+            }
+        }
     } else {
         pub struct Thread(!);
     }