Skip to content

Commit 7ff7ecc

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 6b21c5f commit 7ff7ecc

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
@@ -921,26 +921,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
921921
val: PrimVal,
922922
dest_ty: Ty<'tcx>,
923923
) -> EvalResult<'tcx> {
924-
match dest {
925-
Lvalue::Ptr { ptr, extra } => {
926-
assert_eq!(extra, LvalueExtra::None);
927-
let size = self.type_size(dest_ty)?.expect("dest type must be sized");
928-
self.memory.write_primval(ptr, val, size)
929-
}
930-
Lvalue::Local { frame, local, field } => {
931-
self.stack[frame].set_local(local, field.map(|(i, _)| i), Value::ByVal(val));
932-
Ok(())
933-
}
934-
Lvalue::Global(cid) => {
935-
let global_val = self.globals.get_mut(&cid).expect("global not cached");
936-
if global_val.mutable {
937-
global_val.value = Value::ByVal(val);
938-
Ok(())
939-
} else {
940-
Err(EvalError::ModifiedConstantMemory)
941-
}
942-
}
943-
}
924+
self.write_value(Value::ByVal(val), dest, dest_ty)
944925
}
945926

946927
pub(super) fn write_value(

0 commit comments

Comments
 (0)