Skip to content

DeferMut for Imp is unsound #2

@zakarumych

Description

@zakarumych

This simple code produces undefined behavior without unsafe code involved.

use interior_mutability_pointer::Imp;

fn main() {
    let mut a = Imp::new(vec![1]);
    let mut b = a.clone();

    let x = &mut a[0];
    b.clear();
    b.shrink_to_fit();

    println!("{}", *x); // USE AFTER FREE
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions