Skip to content
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

Fix memory leaks #439

Closed
RalfJung opened this issue Aug 21, 2018 · 2 comments
Closed

Fix memory leaks #439

RalfJung opened this issue Aug 21, 2018 · 2 comments

Comments

@RalfJung
Copy link
Member

The leak check is currently disabled because most tests would fail. I looked at that for run-pass/strings.rs. The remaining non-static allocations at the end are

TRACE 2018-08-20T20:45:40Z: rustc_mir::interpret::memory: Alloc 336:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 (16 bytes, alignment 8) (stack)
TRACE 2018-08-20T20:45:40Z: rustc_mir::interpret::memory:             └────────(303)────────┘ 
TRACE 2018-08-20T20:45:40Z: rustc_mir::interpret::memory: Alloc 610:  00 00 00 00 00 00 00 00 0d 00 00 00 00 00 00 00 (16 bytes, alignment 8) (stack)
TRACE 2018-08-20T20:45:40Z: rustc_mir::interpret::memory:             └────────(308)────────┘ 
TRACE 2018-08-20T20:45:40Z: rustc_mir::interpret::memory: Alloc 621:  00 00 00 00 00 00 00 00 (8 bytes, alignment 8) (stack)
TRACE 2018-08-20T20:45:40Z: rustc_mir::interpret::memory:             └────────(313)────────┘ 
TRACE 2018-08-20T20:45:40Z: rustc_mir::interpret::memory: Alloc 628:  00 00 00 00 00 00 00 00 (8 bytes, alignment 8) (stack)
TRACE 2018-08-20T20:45:40Z: rustc_mir::interpret::memory:             └────────(318)────────┘ 

These are all (fat or thin) pointers to strings in static memory.

I traced allocation 336 back to where it was created. That happens in statement

_4 = &(promoted[15]: &str)

This is while evaluating

fn empty() -> &'static str {
    ""
}

I am a bit surprised here by the types, it almost looks like _4 has type &&str (it's an & applied to an &str) but maybe that is just printing being odd?

@RalfJung
Copy link
Member Author

Minimal reproducing example:

fn main() {
    let _ = &0;
}

This is definitely related to promotion/statics.

@oli-obk I think miri just marks the statics as Stack in init_static, and it never does something akin to mark_static_initialized like it used to. So they get counted for leaks, and they do not get marked read-only. What would be the best way to fix that?

@bjorn3
Copy link
Member

bjorn3 commented Aug 22, 2018

I think miri just marks the statics as Stack in init_static, and it never does something akin to mark_static_initialized like it used to.

I had to do that to make statics referencing to mutable statics work. Making a static readonly requires copying it to the tcx, which is always readonly.

https://github.com/solson/miri/blob/f0070fca1e47c836cd2c13524a37e0781fd76a3d/src/lib.rs#L406-L480

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants