about summary refs log tree commit diff
diff options
context:
space:
mode:
authorIbraheem Ahmed <ibraheem@ibraheem.ca>2024-02-29 00:56:31 -0500
committerGitHub <noreply@github.com>2024-02-29 00:56:31 -0500
commit9c6a0766be95fc197f4f30764a794eb4d50b649a (patch)
tree4ae63d936073374f729cc713c13152a5895783d5
parentd3d145ea1cae47ad392173f890577788117da3d9 (diff)
downloadrust-9c6a0766be95fc197f4f30764a794eb4d50b649a.tar.gz
rust-9c6a0766be95fc197f4f30764a794eb4d50b649a.zip
document potential memory leak in unbounded channel
-rw-r--r--library/std/src/sync/mpmc/list.rs3
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