Skip to content

Commit 380aafb

Browse files
committed
deallocate old environ
1 parent 7882dfb commit 380aafb

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/machine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub struct MemoryExtra<'tcx> {
8585
/// (helps for debugging memory leaks).
8686
tracked_alloc_id: Option<AllocId>,
8787

88-
/// Place where the `environ` static is stored.
88+
/// Place where the `environ` static is stored. Its value should not change after initialization.
8989
pub(crate) environ: Option<MPlaceTy<'tcx, Tag>>,
9090
}
9191

src/shims/env.rs

+5
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
157157

158158
fn update_environ(&mut self) -> InterpResult<'tcx> {
159159
let this = self.eval_context_mut();
160+
// Deallocate the old value for environ, if it exists.
161+
if let Some(environ) = this.memory.extra.environ {
162+
let old_vars_ptr = this.force_ptr(this.read_scalar(environ.into())?.not_undef()?)?;
163+
this.memory.deallocate(old_vars_ptr, None, MiriMemoryKind::Machine.into())?;
164+
}
160165
// Collect all the pointers to each variable in a vector.
161166
let mut vars: Vec<Scalar<Tag>> = this.machine.env_vars.map.values().map(|&ptr| ptr.into()).collect();
162167
// Add the trailing null pointer.

0 commit comments

Comments
 (0)