Skip to content

Commit 51f209a

Browse files
committed
write_primval used to leak memory if the destination was ByRef
instead of duplicating all the code from `write_value`, we forward to it.
1 parent c4c9ff8 commit 51f209a

File tree

1 file changed

+1
-20
lines changed

1 file changed

+1
-20
lines changed

src/eval_context.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -929,26 +929,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
929929
val: PrimVal,
930930
dest_ty: Ty<'tcx>,
931931
) -> EvalResult<'tcx> {
932-
match dest {
933-
Lvalue::Ptr { ptr, extra } => {
934-
assert_eq!(extra, LvalueExtra::None);
935-
let size = self.type_size(dest_ty)?.expect("dest type must be sized");
936-
self.memory.write_primval(ptr, val, size)
937-
}
938-
Lvalue::Local { frame, local, field } => {
939-
self.stack[frame].set_local(local, field.map(|(i, _)| i), Value::ByVal(val));
940-
Ok(())
941-
}
942-
Lvalue::Global(cid) => {
943-
let global_val = self.globals.get_mut(&cid).expect("global not cached");
944-
if global_val.mutable {
945-
global_val.value = Value::ByVal(val);
946-
Ok(())
947-
} else {
948-
Err(EvalError::ModifiedConstantMemory)
949-
}
950-
}
951-
}
932+
self.write_value(Value::ByVal(val), dest, dest_ty)
952933
}
953934

954935
pub(super) fn write_value(

0 commit comments

Comments
 (0)