1
Fork 0

detect memory leaks

This commit is contained in:
Oliver Schneider 2017-02-14 15:35:13 +01:00
parent 25c3a4fb00
commit 529efc51e8
No known key found for this signature in database
GPG key ID: A69F8D225B3AD7D9
2 changed files with 24 additions and 1 deletions

View file

@ -1510,7 +1510,13 @@ pub fn eval_main<'a, 'tcx: 'a>(
loop {
match ecx.step() {
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) => {
report(tcx, &ecx, e);
return;

View file

@ -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 {