Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions implants/lib/eldritchv2/eldritch-core/src/interpreter/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ pub struct Interpreter {
pub depth: usize,
pub call_stack: Vec<StackFrame>,
pub current_func_name: String,
pub is_scope_owner: bool,
}

impl Drop for Interpreter {
fn drop(&mut self) {
if self.is_scope_owner {
// Break reference cycles by clearing the environment values.
// This drops all variables including functions, which may hold references back to the environment.
self.env.write().values.clear();
self.env.write().parent = None;
}
}
}

impl Default for Interpreter {
Expand Down Expand Up @@ -60,6 +72,7 @@ impl Interpreter {
depth: 0,
call_stack: Vec::new(),
current_func_name: "<module>".to_string(),
is_scope_owner: true,
};

interpreter.load_builtins();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,7 @@ fn builtin_eval(
depth: interp.depth + 1,
call_stack: interp.call_stack.clone(),
current_func_name: "<eval>".to_string(),
is_scope_owner: false,
};

match temp_interp.interpret(&code) {
Expand Down