Skip to content

Commit 42a7080

Browse files
committed
Fix a pthread_t handle leak #114610
1 parent 60713f4 commit 42a7080

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

library/std/src/sys/wasi/thread.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ cfg_if::cfg_if! {
4747
stack_size: libc::size_t,
4848
) -> ffi::c_int;
4949
pub fn pthread_attr_destroy(attr: *mut pthread_attr_t) -> ffi::c_int;
50+
pub fn pthread_detach(thread: pthread_t) -> ffi::c_int;
5051
}
5152
}
5253

@@ -178,6 +179,17 @@ impl Thread {
178179
}
179180
}
180181

182+
cfg_if::cfg_if! {
183+
if #[cfg(target_feature = "atomics")] {
184+
impl Drop for Thread {
185+
fn drop(&mut self) {
186+
let ret = unsafe { libc::pthread_detach(self.id) };
187+
debug_assert_eq!(ret, 0);
188+
}
189+
}
190+
}
191+
}
192+
181193
pub fn available_parallelism() -> io::Result<NonZeroUsize> {
182194
unsupported()
183195
}

0 commit comments

Comments
 (0)