we have to permit deallocation memory for which we hold a read lock (67)

This commit is contained in:
Ralf Jung 2017-07-13 20:50:16 -07:00 committed by Oliver Schneider
parent ee209ccd74
commit 359e5360d8
No known key found for this signature in database
GPG key ID: A69F8D225B3AD7D9

View file

@ -393,11 +393,13 @@ impl<'a, 'tcx> Memory<'a, 'tcx> {
Some(alloc) => alloc,
None => return Err(EvalError::DoubleFree),
};
// It is okay for us to still holds locks on deallocation -- for example, we could store data we own
// in a local, and the local could be deallocated (from StorageDead) before the function returns.
// However, we must have write access to the entire allocation.
alloc.check_locks(self.cur_frame, 0, alloc.bytes.len() as u64, AccessKind::Write)
// However, we should check *something*. For now, we make sure that there is no conflicting write
// lock by another frame. We *have* to permit deallocation if we hold a read lock.
// TODO: Figure out the exact rules here.
alloc.check_locks(self.cur_frame, 0, alloc.bytes.len() as u64, AccessKind::Read)
.map_err(|lock| EvalError::DeallocatedLockedMemory { ptr, lock })?;
if alloc.kind != kind {