all: fix memory leaks
This commit is contained in:
parent
56e3eee629
commit
e5c0916a25
15 changed files with 147 additions and 54 deletions
|
|
@ -158,10 +158,21 @@ impl<T, F: Future<Output = T>> Task<T, F> {
|
|||
let task = data as *const Self;
|
||||
if run {
|
||||
task.deref().run();
|
||||
} else {
|
||||
Self::task_runnable_dropped(task);
|
||||
}
|
||||
Self::dec_ref_count(task);
|
||||
}
|
||||
|
||||
#[cold]
|
||||
unsafe fn task_runnable_dropped(task: *const Self) {
|
||||
let task = task.deref();
|
||||
task.state.and_assign(!RUNNING);
|
||||
if task.state.get() & CANCELLED != 0 {
|
||||
task.drop_data();
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn dec_ref_count(slf: *const Self) {
|
||||
if slf.deref().ref_count.fetch_sub(1) == 1 {
|
||||
Box::from_raw(slf as *mut Self);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue