mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-07 00:00:08 +02:00
sync: fix mem leak in oneshot on task migration (#1648)
When polling the task, the current waker is saved to the oneshot state. When the handle is migrated to a new task and polled again, the waker must be swaped from the old waker to the new waker. In some cases, there is a potential for the old waker to leak. This bug was caught by loom with the recently added memory leak detection.
This commit is contained in:
@@ -171,6 +171,8 @@ impl<T> Sender<T> {
|
|||||||
state = State::unset_tx_task(&inner.state);
|
state = State::unset_tx_task(&inner.state);
|
||||||
|
|
||||||
if state.is_closed() {
|
if state.is_closed() {
|
||||||
|
// Set the flag again so that the waker is released in drop
|
||||||
|
State::set_tx_task(&inner.state);
|
||||||
return Ready(());
|
return Ready(());
|
||||||
} else {
|
} else {
|
||||||
unsafe { inner.drop_tx_task() };
|
unsafe { inner.drop_tx_task() };
|
||||||
@@ -359,6 +361,9 @@ impl<T> Inner<T> {
|
|||||||
// Unset the task
|
// Unset the task
|
||||||
state = State::unset_rx_task(&self.state);
|
state = State::unset_rx_task(&self.state);
|
||||||
if state.is_complete() {
|
if state.is_complete() {
|
||||||
|
// Set the flag again so that the waker is released in drop
|
||||||
|
State::set_rx_task(&self.state);
|
||||||
|
|
||||||
return match unsafe { self.consume_value() } {
|
return match unsafe { self.consume_value() } {
|
||||||
Some(value) => Ready(Ok(value)),
|
Some(value) => Ready(Ok(value)),
|
||||||
None => Ready(Err(RecvError(()))),
|
None => Ready(Err(RecvError(()))),
|
||||||
|
|||||||
Reference in New Issue
Block a user