Skip to content

Commit ad06933

Browse files
committed
fix & no mem leaks
1 parent 5cec48e commit ad06933

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

zenlang/src/vm/vm.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,22 @@ impl VM {
184184
if self.environs.len() == 0 {
185185
panic!("pop_environment: environs is empty");
186186
}
187-
(&mut *self.environs.last().unwrap().borrow_mut())
188-
.vars
189-
.clear();
187+
// Fuck reference counted ptrs
188+
// Why do I have to count references, MANUALLY
189+
// (there is probably a better way to do this, but time's ticking)
190+
let environ = self.environs.last().unwrap();
191+
let mut refs: usize = 0;
192+
for e in self.environs.iter() {
193+
if Rc::ptr_eq(e, environ) {
194+
refs += 1;
195+
}
196+
}
197+
198+
// If refs != 1, the vars are prolly used somewhere else so don't clear them
199+
if refs == 1 {
200+
(&mut *environ.borrow_mut()).vars.clear();
201+
}
202+
190203
self.environs.pop();
191204
}
192205

0 commit comments

Comments
 (0)