document potential memory leak in unbounded channel

This commit is contained in:
Ibraheem Ahmed 2024-02-29 00:56:31 -05:00 committed by GitHub
parent d3d145ea1c
commit 9c6a0766be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -547,6 +547,9 @@ fn discard_all_messages(&self) {
}
let mut head = self.head.index.load(Ordering::Acquire);
// the channel may be uninitialized, so we have to swap to avoid overwriting any sender's attempts
// to initalize the first block before noticing that the receivers disconnected. late allocations
// will be deallocated by the sender in Drop
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