memory reachable through globals is not a leak any more; adjust for better memory dumping
This commit is contained in:
parent
d25589f0bd
commit
f462b4c257
3 changed files with 34 additions and 14 deletions
|
|
@ -6,6 +6,7 @@ use std::cell::RefCell;
|
|||
use std::num::NonZeroU64;
|
||||
use std::rc::Rc;
|
||||
use std::time::Instant;
|
||||
use std::fmt;
|
||||
|
||||
use log::trace;
|
||||
use rand::rngs::StdRng;
|
||||
|
|
@ -62,6 +63,31 @@ impl Into<MemoryKind<MiriMemoryKind>> for MiriMemoryKind {
|
|||
}
|
||||
}
|
||||
|
||||
impl MayLeak for MiriMemoryKind {
|
||||
#[inline(always)]
|
||||
fn may_leak(self) -> bool {
|
||||
use self::MiriMemoryKind::*;
|
||||
match self {
|
||||
Rust | C | WinHeap | Env => false,
|
||||
Machine | Global => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for MiriMemoryKind {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
use self::MiriMemoryKind::*;
|
||||
match self {
|
||||
Rust => write!(f, "Rust heap"),
|
||||
C => write!(f, "C heap"),
|
||||
WinHeap => write!(f, "Windows heap"),
|
||||
Machine => write!(f, "machine-managed memory"),
|
||||
Env => write!(f, "environment variable"),
|
||||
Global => write!(f, "global"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Extra per-allocation data
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AllocExtra {
|
||||
|
|
@ -491,14 +517,3 @@ impl AllocationExtra<Tag> for AllocExtra {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MayLeak for MiriMemoryKind {
|
||||
#[inline(always)]
|
||||
fn may_leak(self) -> bool {
|
||||
use self::MiriMemoryKind::*;
|
||||
match self {
|
||||
Rust | C | WinHeap | Env => false,
|
||||
Machine | Global => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
8
tests/run-pass/leak-in-static.rs
Normal file
8
tests/run-pass/leak-in-static.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
static mut LEAKER: Option<Box<Vec<i32>>> = None;
|
||||
|
||||
fn main() {
|
||||
// Having memory "leaked" in globals is allowed.
|
||||
unsafe {
|
||||
LEAKER = Some(Box::new(vec![0; 42]));
|
||||
}
|
||||
}
|
||||
|
|
@ -77,9 +77,6 @@ fn main() {
|
|||
test(None, |_old_val| { debug_assert!(false); loop {} });
|
||||
test(None, |_old_val| { unsafe { (1 as *const i32).read() }; loop {} }); // trigger debug-assertion in libstd
|
||||
|
||||
// Cleanup: reset to default hook.
|
||||
drop(std::panic::take_hook());
|
||||
|
||||
eprintln!("Success!"); // Make sure we get this in stderr
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue