diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2024-02-29 05:25:29 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-29 05:25:29 -0500 |
| commit | 20a1bf6c17cf35ffcc8976f8665cb149b6b6429a (patch) | |
| tree | fbd06a865175f1da55f2f4dd78633180dce07d21 | |
| parent | d6e0f5cb0c9e293861a7c6feaa67ccd181bda54a (diff) | |
| parent | 7c9fa952c3be1f7d0872fe9cd5f1f4a0327771b9 (diff) | |
| download | rust-20a1bf6c17cf35ffcc8976f8665cb149b6b6429a.tar.gz rust-20a1bf6c17cf35ffcc8976f8665cb149b6b6429a.zip | |
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.
| -rw-r--r-- | library/std/src/sync/mpmc/list.rs | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/library/std/src/sync/mpmc/list.rs b/library/std/src/sync/mpmc/list.rs index a1b275112a1..9e7148c716c 100644 --- a/library/std/src/sync/mpmc/list.rs +++ b/library/std/src/sync/mpmc/list.rs @@ -547,6 +547,9 @@ impl<T> Channel<T> { } 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 |
