Skip to content

Commit 4152918

Browse files
committed
runtime: fix leak in UnownedTask
1 parent c0974ba commit 4152918

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

tokio/src/runtime/task/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,16 @@ impl<S: Schedule> UnownedTask<S> {
369369
let raw = self.raw;
370370
mem::forget(self);
371371

372-
// Poll the task
372+
// Transfer one ref-count to a Task object.
373+
let task = Task::<S> {
374+
raw,
375+
_p: PhantomData,
376+
};
377+
378+
// Use the other ref-count to poll the task.
373379
raw.poll();
374380
// Decrement our extra ref-count
375-
raw.header().state.ref_dec();
381+
drop(task);
376382
}
377383

378384
pub(crate) fn shutdown(self) {

tokio/src/runtime/tests/task.rs

+6
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ fn create_shutdown2() {
111111
drop(join);
112112
}
113113

114+
#[test]
115+
fn unowned_poll() {
116+
let (task, _) = unowned(async {}, NoopSchedule);
117+
task.run();
118+
}
119+
114120
#[test]
115121
fn schedule() {
116122
with(|rt| {

0 commit comments

Comments
 (0)