miri: don't report memory leaks for static data
Currently, miri reports a memory leak for a static with heap allocated data. This is somewhat expected, as statics don’t run destructors and indeed leak memory. However, this is not error, and ideally shouldn’t be reported by miri as such.
See https://github.com/matklad/once_cell/pull/45/commits/327f4e24678b5930d129e79b61023a33499961be for an example.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 22 (15 by maintainers)
Commits related to this issue
- Ignore memory leaks from miri These are probably spurious; see https://github.com/crossbeam-rs/crossbeam/issues/464 and https://github.com/spacejam/sled/pull/937#issuecomment-578556658 And besides, ... — committed to jonhoo/flurry by jonhoo 4 years ago
- Auto merge of #1301 - RalfJung:global-leaks, r=RalfJung memory reachable through globals is not a leak Blocked on https://github.com/rust-lang/rust/pull/70762 Fixes https://github.com/rust-lang/miri... — committed to rust-lang/miri by bors 4 years ago
- Stop ignoring miri leaks Now that https://github.com/rust-lang/miri/issues/940 has been fixed, and has landed in nightly (https://github.com/rust-lang/rust/pull/70897), we should be able to run miri ... — committed to jonhoo/flurry by jonhoo 4 years ago
- Merge #99 99: miri: enable leakcheck r=matklad a=RalfJung https://github.com/rust-lang/miri/issues/940 is fixed, so we should be able to enable the leak checker now. :) (However, we'll have to wa... — committed to matklad/once_cell by bors[bot] 4 years ago
- Move away from pointers as usize Pointers stored as `usize` tend to cause miri to lose pointer provenance tracking, which means we can't take advantage of its checking! See also the discussion at htt... — committed to jonhoo/crossbeam by jonhoo 4 years ago
- Stop ignoring miri leaks Now that https://github.com/rust-lang/miri/issues/940 has been fixed, and has landed in nightly (https://github.com/rust-lang/rust/pull/70897), we should be able to run miri ... — committed to jonhoo/flurry by jonhoo 4 years ago
To avoid continuing this discussion in a closed issue, I opened https://github.com/rust-lang/miri/issues/1318.
Yeah, I agree that would be sad. However, re-adding that code might be even more sad.^^
See
ptr_int_arithmeticremoved in this commit for the awful things we used to do.Ah, yes raw pointers may be NULL, dangling and unaligned, that is fine, as long as they do not get dereferenced (
*operator – even when no memory access happens).They might also be using
AtomicPtrwhich under the hood does a cast tousize– see https://github.com/rust-lang/rust/pull/70765.Oh, heh. I never thought about heap pointers being leaked into statics. Also calls to
Box::leakshould probably not trigger the leak errors.Maybe we should, before running the check, recursively mark anything reachable by a static as static itself.
And we should add a hook to
Box::leakto make it mark its memory as static (we can userustc_diagnostic_itemto get theDefIdofBox::leak