-
Notifications
You must be signed in to change notification settings - Fork 51
Open
Description
This is a reproduction:
// async-task v4.4.0
impl RawTask {
unsafe fn destory(ptr: _) {
// ...
// Finally, deallocate the memory reserved by the task.
alloc::alloc::dealloc(ptr as *mut u8, task_layout.layout);
std::eprintln!("destroyed, ptr: {:p}", ptr);
}
}
// async-executor
#[cfg(test)]
mod tests {
use super::*;
use std::boxed::Box;
#[test]
fn task_refs() {
let ex: &'static StaticExecutor = Box::leak(Box::new(StaticExecutor::new()));
// let ex = Executor::new();
{
ex.spawn(async move {
futures_lite::future::pending::<()>().await;
unreachable!();
})
.detach();
}
for _ in 0..100 {
ex.try_tick();
}
std::mem::forget(ex);
}
}Run test task_refs, we can see the destroyed, ptr: .. printed, if we use Executor, it will not print. I guess this is a bug?
The reference count of task is 1, and in the last of RawTask::run, it go through this line: https://github.com/smol-rs/async-task/blob/a11c4b22cbcbbdbc4fa0ff62bdbffb430a9d3394/src/raw.rs#L664 , so the task's memory was dealloced.
Maybe relevant PR: #112
Metadata
Metadata
Assignees
Labels
No labels