From ea56cc0ce8cfbe999872e371acfcc7fb86a0e839 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Tue, 18 Mar 2025 22:24:10 +0100 Subject: [PATCH] rtic-sync: `take` link if it is popped --- rtic-sync/src/channel.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/rtic-sync/src/channel.rs b/rtic-sync/src/channel.rs index d3a64b6f1c2..0aeb4a4ea66 100644 --- a/rtic-sync/src/channel.rs +++ b/rtic-sync/src/channel.rs @@ -366,11 +366,16 @@ impl Sender<'_, T, N> { let link = unsafe { link_ptr.get() }; // We are already in the wait queue. - if let Some(link) = link { - if link.is_popped() { + if let Some(queue_link) = link { + if queue_link.is_popped() { // SAFETY: `free_slot_ptr` is valid for writes until the end of this future. let slot = unsafe { free_slot_ptr.replace(None, cs) }; + // Our link was popped, so it is most definitely not in the list. + // We can safely & correctly `take` it to prevent ourselves from + // redundantly attempting to remove it from the list a 2nd time. + link.take(); + // If our link is popped, then: // 1. We were popped by `return_free_lot` and provided us with a slot. // 2. We were popped by `Receiver::drop` and it did not provide us with a slot, and the channel is closed.