bacon-rajan-cc
bacon-rajan-cc copied to clipboard
trace Rc, rc::Weak, Arc, sync::Weak, Mutex
Tracing the content of Rc
, Arc
, etc. is unsound and will lead to double frees, since it is like tracing the same field twice or more:
struct A {
rc1: Rc<Cc<B>>,
rc2: Rc<Cc<B>>,
}
struct B {
...
}
impl Trace for A {
fn trace(&self, tracer: &mut Tracer) {
self.rc1.trace(tracer);
self.rc2.trace(tracer);
}
}
fn main() {
let b = Rc::new(Cc::new(B { ... }));
let a = Cc::new(A {
rc1: b.clone(),
rc2: b.clone(),
});
// Now tracing a is unsound, since b strong counter is 1 and b will be traced twice
}
This is also why in rust-cc there isn't a Trace
impl for Rc
.