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 } }