Open
Description
The following is part of the native Thread::new
implementation on Windows:
// https://github.com/rust-lang/rust/blob/master/library/std/src/sys/pal/windows/thread.rs#L30
let ret = c::CreateThread(
ptr::null_mut(),
stack,
Some(thread_start),
p as *mut _,
c::STACK_SIZE_PARAM_IS_A_RESERVATION,
ptr::null_mut(),
);
let ret = HandleOrNull::from_raw_handle(ret);
return if let Ok(handle) = ret.try_into() {
Ok(Thread { handle: Handle::from_inner(handle) })
} else {
// The thread failed to start and as a result p was not consumed. Therefore, it is
// safe to reconstruct the box so that it gets deallocated.
drop(Box::from_raw(p));
Err(io::Error::last_os_error())
};
If drop(Box::from_raw(p));
panics, then the error is not returned. I suggest to replace the drop
statement with:
panic::catch_unwind(AssertUnwindSafe(|| drop(Box::from_raw(p))));