From 63d5df6c0733627d1d4727a52fa0222e57ce0616 Mon Sep 17 00:00:00 2001 From: life_robot Date: Wed, 23 Sep 2026 15:04:46 +0800 Subject: [PATCH] 1. fix: gate SyncVec::iter() promote on amended flag to prevent retired snapshot leak --- src/sync/vec.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/sync/vec.rs b/src/sync/vec.rs index 283dfb0..981bc4c 100644 --- a/src/sync/vec.rs +++ b/src/sync/vec.rs @@ -360,12 +360,15 @@ impl SyncVec { r } - /// Iterate over the current contents. A fresh snapshot is published first, - /// so all elements written so far are visible. + /// Iterate over the current contents. If dirty has un-published writes, a + /// fresh snapshot is published first; otherwise the current snapshot is + /// reused lock-free to avoid leaking retired Box allocations on every call. pub fn iter(&self) -> Iter<'_, V> { - let g = self.lock.lock(); - self.promote(); - drop(g); + if self.amended.load(Ordering::Acquire) { + let g = self.lock.lock(); + self.promote(); + drop(g); + } Iter { inner: self.read.load().iter(), }