Skip to content

Commit 96bd6ef

Browse files
committed
memory reachable through globals is not a leak any more; adjust for better memory dumping
1 parent 147ea8f commit 96bd6ef

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

src/machine.rs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::cell::RefCell;
66
use std::num::NonZeroU64;
77
use std::rc::Rc;
88
use std::time::Instant;
9+
use std::fmt;
910

1011
use log::trace;
1112
use rand::rngs::StdRng;
@@ -62,6 +63,31 @@ impl Into<MemoryKind<MiriMemoryKind>> for MiriMemoryKind {
6263
}
6364
}
6465

66+
impl MayLeak for MiriMemoryKind {
67+
#[inline(always)]
68+
fn may_leak(self) -> bool {
69+
use self::MiriMemoryKind::*;
70+
match self {
71+
Rust | C | WinHeap | Env => false,
72+
Machine | Global => true,
73+
}
74+
}
75+
}
76+
77+
impl fmt::Display for MiriMemoryKind {
78+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
79+
use self::MiriMemoryKind::*;
80+
match self {
81+
Rust => write!(f, "Rust heap"),
82+
C => write!(f, "C heap"),
83+
WinHeap => write!(f, "Windows heap"),
84+
Machine => write!(f, "machine-managed memory"),
85+
Env => write!(f, "environment variable"),
86+
Global => write!(f, "global"),
87+
}
88+
}
89+
}
90+
6591
/// Extra per-allocation data
6692
#[derive(Debug, Clone)]
6793
pub struct AllocExtra {
@@ -491,14 +517,3 @@ impl AllocationExtra<Tag> for AllocExtra {
491517
}
492518
}
493519
}
494-
495-
impl MayLeak for MiriMemoryKind {
496-
#[inline(always)]
497-
fn may_leak(self) -> bool {
498-
use self::MiriMemoryKind::*;
499-
match self {
500-
Rust | C | WinHeap | Env => false,
501-
Machine | Global => true,
502-
}
503-
}
504-
}

tests/run-pass/leak-in-static.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
static mut LEAKER: Option<Box<Vec<i32>>> = None;
2+
3+
fn main() {
4+
// Having memory "leaked" in globals is allowed.
5+
unsafe {
6+
LEAKER = Some(Box::new(vec![0; 42]));
7+
}
8+
}

tests/run-pass/panic/catch_panic.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ fn main() {
7777
test(None, |_old_val| { debug_assert!(false); loop {} });
7878
test(None, |_old_val| { unsafe { (1 as *const i32).read() }; loop {} }); // trigger debug-assertion in libstd
7979

80-
// Cleanup: reset to default hook.
81-
drop(std::panic::take_hook());
82-
8380
eprintln!("Success!"); // Make sure we get this in stderr
8481
}
8582

0 commit comments

Comments
 (0)