1
0
Fork 0
forked from wry/wry

all: fix memory leaks

This commit is contained in:
Julian Orth 2022-05-18 22:42:36 +02:00
parent 56e3eee629
commit e5c0916a25
15 changed files with 147 additions and 54 deletions

View file

@ -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);