-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Possible to leak a non-static reference into a sendable proc #19261
Comments
Nominating. |
I believe this to be a problem specifically with
Running on Win x86, with
Running with
This suggests that the allocation behind the temporary string is being freed and then re-used, despite still holding a borrowed reference. Note: this code does not pass borrow checking on
Which suggests a recent regression. This particular case was found by I should also note that I was incredibly lucky with this: making the |
A smaller form of the same bug: fn staticify<T>(x: &T) -> &'static T {
x.clone()
} This is obviously not safe, and allows one to leak references into (This was discovered by tamird and bluss on IRC.) |
cc @glennpratt |
This is probably not specific to static lifetimes, as this passes: fn leak<'a, T>(x: T) -> &'a T {
(&x).clone()
} I'm returning a reference to what is essentially a local variable! Not good, not good at all. |
Rather simple example
|
1.0, P-backcompat-lang. fix enqueued. |
**First commit.** Patch up debruijn indices. Fixes #19537. **Second commit.** Stop reborrowing so much. Fixes #19147. Fixes #19261. r? @nick29581
This successfully compiles, even though inner is a
&Foo
.For a more real example, see sfackler/r2d2@d864a78. It'll cause tests to segfault ~50% of the time.
The text was updated successfully, but these errors were encountered: