From b1094f6c1e59f5cc87c354c7790cbf96c377b53f Mon Sep 17 00:00:00 2001 From: Scott Olson Date: Sun, 16 Oct 2016 03:21:41 -0600 Subject: [PATCH] Deallocate primval conversion hack allocs. It's a hack, sure, but it should learn some manners. --- src/interpreter/mod.rs | 4 +++- tests/compile-fail/oom2.rs | 11 ++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index a681e64d32c..d9d3cba31c0 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -1124,7 +1124,9 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { Value::ByVal(primval) => { let ptr = self.alloc_ptr(ty)?; self.memory.write_primval(ptr, primval)?; - self.value_to_primval(Value::ByRef(ptr), ty) + let primval = self.value_to_primval(Value::ByRef(ptr), ty)?; + self.memory.deallocate(ptr)?; + Ok(primval) } Value::ByValPair(..) => bug!("value_to_primval can't work with fat pointers"), diff --git a/tests/compile-fail/oom2.rs b/tests/compile-fail/oom2.rs index b89231e4515..d2498294252 100644 --- a/tests/compile-fail/oom2.rs +++ b/tests/compile-fail/oom2.rs @@ -2,7 +2,7 @@ #![miri(memory_size=1000)] fn bar(i: i32) { - if i < 1000 { //~ERROR tried to allocate 4 more bytes, but only 1 bytes are free of the 1000 byte memory + if i < 1000 { //~ERROR tried to allocate 4 more bytes, but only 0 bytes are free of the 1000 byte memory bar(i + 1) //~^NOTE inside call to bar //~|NOTE inside call to bar @@ -31,6 +31,15 @@ fn bar(i: i32) { //~|NOTE inside call to bar //~|NOTE inside call to bar //~|NOTE inside call to bar + //~|NOTE inside call to bar + //~|NOTE inside call to bar + //~|NOTE inside call to bar + //~|NOTE inside call to bar + //~|NOTE inside call to bar + //~|NOTE inside call to bar + //~|NOTE inside call to bar + //~|NOTE inside call to bar + //~|NOTE inside call to bar } }