Skip to content

Commit

Permalink
reject deallocation of read-only allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed May 23, 2021
1 parent 6e92fb4 commit 3bcba11
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler/rustc_mir/src/interpret/memory.rs
Expand Up @@ -321,6 +321,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
}
};

if alloc.mutability == Mutability::Not {
throw_ub_format!("deallocating immutable allocation {}", ptr.alloc_id);
}
if alloc_kind != kind {
throw_ub_format!(
"deallocating {}, which is {} memory, using {} deallocation operation",
Expand Down

0 comments on commit 3bcba11

Please sign in to comment.