From d10304eeb5c9e63597b9ee1094aca0f63c4f31ca Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 29 Oct 2018 20:40:19 +0100 Subject: [PATCH] the memory_deallocated hook can make good use of knowing the size --- src/librustc_mir/interpret/machine.rs | 1 + src/librustc_mir/interpret/memory.rs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/librustc_mir/interpret/machine.rs b/src/librustc_mir/interpret/machine.rs index 7aeadfa408a9..e9d181479e52 100644 --- a/src/librustc_mir/interpret/machine.rs +++ b/src/librustc_mir/interpret/machine.rs @@ -199,6 +199,7 @@ pub trait Machine<'a, 'mir, 'tcx>: Sized { fn memory_deallocated( _alloc: &mut Allocation, _ptr: Pointer, + _size: Size, ) -> EvalResult<'tcx> { Ok(()) } diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index 91f3813e2b1f..a9ef35845fc8 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -232,7 +232,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> { } // Let the machine take some extra action - M::memory_deallocated(&mut alloc, ptr)?; + let size = Size::from_bytes(alloc.bytes.len() as u64); + M::memory_deallocated(&mut alloc, ptr, size)?; // Don't forget to remember size and align of this now-dead allocation let old = self.dead_alloc_map.insert(