diff --git a/crossbeam-channel/src/flavors/list.rs b/crossbeam-channel/src/flavors/list.rs index f6a79f719..6d7ba7ebf 100644 --- a/crossbeam-channel/src/flavors/list.rs +++ b/crossbeam-channel/src/flavors/list.rs @@ -583,7 +583,7 @@ impl Channel { } let mut head = self.head.index.load(Ordering::Acquire); - let mut block = self.head.block.load(Ordering::Acquire); + let mut block = self.head.block.swap(ptr::null_mut(), Ordering::AcqRel); // If we're going to be dropping messages we need to synchronize with initialization if head >> SHIFT != tail >> SHIFT { @@ -596,6 +596,7 @@ impl Channel { block = self.head.block.load(Ordering::Acquire); } } + unsafe { // Drop all messages between head and tail and deallocate the heap-allocated blocks. while head >> SHIFT != tail >> SHIFT { @@ -623,7 +624,6 @@ impl Channel { } } head &= !MARK_BIT; - self.head.block.store(ptr::null_mut(), Ordering::Release); self.head.index.store(head, Ordering::Release); }