Skip to content

AtomicOption is not memory safe #19247

Closed
@pythonesque

Description

@pythonesque

I was playing around with AtomicOption and realized that it does not require the correct bound (which I believe should be Send) for its type parameter. Thus, you can do this:

use std::sync::atomic::{AtomicOption, SeqCst};

struct Foo<'a> { foo: AtomicOption<&'a Foo<'a>>, id: Box<u8> }

fn main() {
    let foo = Foo { foo: AtomicOption::empty(), id: box 10 };
    foo.foo.fill(box &foo, SeqCst);
    spawn(proc() {
        let foo = foo;
        println!("{}", foo.foo.take(SeqCst).unwrap().id);
    });
}

Segmentation fault: 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions