Skip to content

Use after free with mutable owned pointers #11192

New issue

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

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

Already on GitHub? # to your account

Closed
evanw opened this issue Dec 29, 2013 · 5 comments · Fixed by #12738
Closed

Use after free with mutable owned pointers #11192

evanw opened this issue Dec 29, 2013 · 5 comments · Fixed by #12738
Labels
A-lifetimes Area: Lifetimes / regions E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@evanw
Copy link

evanw commented Dec 29, 2013

This code compiles and runs but seems to allow a use-after-free:

struct Foo {
  x: int
}

impl Drop for Foo {
  fn drop(&mut self) {
    println!("drop {}", self.x);
  }
}

fn main() {
  let mut ptr = ~Foo { x: 0 };
  let test = |foo: &Foo| {
    println!("access {}", foo.x);
    ptr = ~Foo { x: ptr.x + 1 };
    println!("access {}", foo.x);
  };
  test(ptr);
}

The output is:

access 0
drop 0
access 0
drop 1

This is with rustc 0.8. It may be related to #9853 but I'm not sure.

@thestinger
Copy link
Contributor

cc @nikomatsakis

@ben0x539
Copy link
Contributor

Maybe similar to #10398 too

@nikomatsakis
Copy link
Contributor

This is #2202, I believe. I'll leave it open to verify.

@nikomatsakis
Copy link
Contributor

More specifically fixed by #6801

@alexcrichton
Copy link
Member

This has been fixed, flagging as needstest.

bors added a commit that referenced this issue Mar 6, 2014
Closes #6738
Closes #7061
Closes #7899
Closes #9719
Closes #10028
Closes #10228
Closes #10401
Closes #11192
Closes #11508
Closes #11529
Closes #11873
Closes #11925
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-lifetimes Area: Lifetimes / regions E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants