shrink_to_fit some vectors to prevent interpreted code from passing the memory limits

上级 8d3817cf
......@@ -179,12 +179,11 @@ pub fn reallocate(&mut self, ptr: Pointer, new_size: usize) -> EvalResult<'tcx,
alloc.bytes.extend(iter::repeat(0).take(amount));
alloc.undef_mask.grow(amount, false);
} else if size > new_size {
// it's possible to cause miri to use arbitrary amounts of memory that aren't detectable
// through the memory_usage value, by allocating a lot and reallocating to zero
self.memory_usage -= size - new_size;
self.clear_relocations(ptr.offset(new_size as isize), size - new_size)?;
let alloc = self.get_mut(ptr.alloc_id)?;
alloc.bytes.truncate(new_size);
alloc.bytes.shrink_to_fit();
alloc.undef_mask.truncate(new_size);
}
......@@ -676,6 +675,7 @@ fn grow(&mut self, amount: usize, new_state: bool) {
fn truncate(&mut self, length: usize) {
self.len = length;
self.blocks.truncate(self.len / BLOCK_SIZE + 1);
self.blocks.shrink_to_fit();
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册