crossbeam-arccell
crossbeam-arccell copied to clipboard
Cloning an ArcCell causes the value inside being dropped multiple times.
In its Drop implementation, ArcCell<T> unconditionally creates an owned T from the atomic pointer it holds. Therefore, cloning an ArcCell<T> will cause the T to be dropped twice, leading to undefined behavior. The following code demonstrates this, as it prints "drop" twice (or it might segfault).
struct NoisyDrop;
impl Drop for NoisyDrop {
fn drop(&mut self) { println!("drop!"); }
}
fn main() {
let v = crossbeam_arccell::ArcCell::new(NoisyDrop);
let _v = v.clone();
}
Good find! I'll see what needs to be done to fix this up - hopefully just an AtomicBool to see whether or not it's already been dropped (as I believe crossbeam-epoch should handle the rest).