crossbeam-arccell icon indicating copy to clipboard operation
crossbeam-arccell copied to clipboard

Cloning an ArcCell causes the value inside being dropped multiple times.

Open whentze opened this issue 7 years ago • 1 comments

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();
}

whentze avatar Nov 22 '18 07:11 whentze

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).

k3d3 avatar Dec 16 '18 21:12 k3d3