Closed
Description
The following creates a dangling pointer to an outer stack frame:
use std::cell::Cell;
struct Foo<'a> {
x: int,
y: Cell<Option<&'a int>>,
}
fn f() -> Foo {
Foo {
x: 1,
y: Cell::new(None),
}
}
fn g<'a>(x: &'a Foo<'a>) {
x.y.set(Some(&x.x));
}
fn h() -> Foo {
let x = f();
g(&x);
x
}
fn main() {
let x = h();
// kaboom
}
This manifested as a rustc segfault.