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

Unsound: AtomSetOnce::dup is not panic safe #18

Open
yvt opened this issue Oct 9, 2021 · 0 comments
Open

Unsound: AtomSetOnce::dup is not panic safe #18

yvt opened this issue Oct 9, 2021 · 0 comments

Comments

@yvt
Copy link

yvt commented Oct 9, 2021

#[test]
fn dup_panic_safety() {
    struct WeirdTy(String);

    impl Clone for WeirdTy {
        fn clone(&self) -> Self {
            panic!("")
        }
    }

    let x = AtomSetOnce::new(Box::new(WeirdTy("hoge".to_owned())));
    std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
        x.dup(Ordering::Acquire); // `v.clone()` panics, skipping `mem::forget(v)` and dropping `Box<WeirdTy>`
    }));
    // The `Box<WeirdTy>` is dropped again, causing a double-free
}
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

No branches or pull requests

1 participant