miri: Memory leak checker misses AtomicPtr
use std::{
cell::UnsafeCell,
ptr,
sync::atomic::{AtomicPtr, Ordering},
};
fn leak() {
static LEAK: AtomicPtr<usize> = AtomicPtr::new(ptr::null_mut());
LEAK.store(Box::into_raw(Box::new(0usize)), Ordering::SeqCst);
}
fn no_leak() {
struct Local(UnsafeCell<*mut usize>);
unsafe impl Send for Local {}
unsafe impl Sync for Local {}
static LEAK: Local = Local(UnsafeCell::new(ptr::null_mut()));
*unsafe { &mut *LEAK.0.get() } = Box::into_raw(Box::new(0usize));
}
fn main() {
no_leak();
// leak();
}
Miri considers memory leaks reachable through a static global as non-leaking. Iād expect the Atomic* case be non-leaking as well, however miri reports it as leaked memory.
The following memory was leaked: alloc1834 (Rust heap, size: 8, align: 8) {
00 00 00 00 00 00 00 00 ā ........
}
error: the evaluated program leaked memory
error: aborting due to previous error; 1 warning emitted
(This is a special case of https://github.com/rust-lang/miri/issues/1618.)
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18 (14 by maintainers)
Commits related to this issue
- Auto merge of #77611 - oli-obk:atomic_miri_leakage, r=nagisa Directly use raw pointers in `AtomicPtr` store/load I was unable to find any reason for this limitation in the latest source of LLVM or i... — committed to rust-lang-ci/rust by bors 4 years ago
- Auto merge of #77611 - oli-obk:atomic_miri_leakage, r=nagisa Directly use raw pointers in `AtomicPtr` store/load I was unable to find any reason for this limitation in the latest source of LLVM or i... — committed to rust-lang/rustc_codegen_cranelift by bors 4 years ago
- Note about -Zmiri-track-raw-pointers I'm also double-checking in https://github.com/rust-lang/miri/issues/1574#issuecomment-1053752658. — committed to jonhoo/haphazard by jonhoo 2 years ago
Please open a new issue with a pointer to the relevant code. š
Yes. We need to fix this in libstd/rustc, miri is doing the right thing ā¢ļø and implementing workarounds just on the miri side is not feasible afaict