detect memory leaks
This commit is contained in:
parent
25c3a4fb00
commit
529efc51e8
2 changed files with 24 additions and 1 deletions
|
@ -1510,7 +1510,13 @@ pub fn eval_main<'a, 'tcx: 'a>(
|
||||||
loop {
|
loop {
|
||||||
match ecx.step() {
|
match ecx.step() {
|
||||||
Ok(true) => {}
|
Ok(true) => {}
|
||||||
Ok(false) => return,
|
Ok(false) => {
|
||||||
|
let leaks = ecx.memory.leak_report();
|
||||||
|
if leaks != 0 {
|
||||||
|
tcx.sess.err("the evaluated program leaked memory");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
report(tcx, &ecx, e);
|
report(tcx, &ecx, e);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -585,6 +585,23 @@ impl<'a, 'tcx> Memory<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn leak_report(&self) -> usize {
|
||||||
|
trace!("### LEAK REPORT ###");
|
||||||
|
let leaks: Vec<_> = self.alloc_map
|
||||||
|
.iter()
|
||||||
|
.filter_map(|(&key, val)| {
|
||||||
|
if val.static_kind == StaticKind::NotStatic {
|
||||||
|
Some(key)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
let n = leaks.len();
|
||||||
|
self.dump_allocs(leaks);
|
||||||
|
n
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dump_fn_def<'tcx>(fn_def: FunctionDefinition<'tcx>) -> String {
|
fn dump_fn_def<'tcx>(fn_def: FunctionDefinition<'tcx>) -> String {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue