Rollup merge of #121778 - ibraheemdev:patch-19, r=RalfJung

Document potential memory leak in unbounded channel

Follow up on https://github.com/rust-lang/rust/pull/121646.
This commit is contained in:
Jacob Pratt 2024-02-29 05:25:29 -05:00 committed by GitHub
commit 20a1bf6c17
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