Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trace Rc, rc::Weak, Arc, sync::Weak, Mutex #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mio-19
Copy link
Contributor

@mio-19 mio-19 commented Mar 29, 2020

No description provided.

@mio-19 mio-19 changed the title use read().unwrap() instead of if let Ok(v) = self.write() for RwLock. trace Rc, rc::Weak, Arc, sync::Weak, Mutex trace Rc, rc::Weak, Arc, sync::Weak, Mutex Mar 30, 2020
@frengor
Copy link

frengor commented Mar 17, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants