diff options
| author | Ibraheem Ahmed <ibraheem@ibraheem.ca> | 2024-02-29 00:56:31 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-29 00:56:31 -0500 |
| commit | 9c6a0766be95fc197f4f30764a794eb4d50b649a (patch) | |
| tree | 4ae63d936073374f729cc713c13152a5895783d5 | |
| parent | d3d145ea1cae47ad392173f890577788117da3d9 (diff) | |
| download | rust-9c6a0766be95fc197f4f30764a794eb4d50b649a.tar.gz rust-9c6a0766be95fc197f4f30764a794eb4d50b649a.zip | |
document potential memory leak in unbounded channel
| -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..b6bae7dc50c 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 |
