Clears the AVM1 stack after executing bytecode

AVM1 bytecode may leave the operand stack unbalanced, and this will
cause a slow memory leak if the stack is never cleared.
This commit is contained in:
Moulins 2022-12-21 03:39:06 +01:00 committed by Nathan Adams
parent c6bd431864
commit 3b1c981d25
2 changed files with 8 additions and 0 deletions

View File

@ -314,6 +314,10 @@ impl<'gc> Avm1<'gc> {
self.stack.len() self.stack.len()
} }
pub fn clear_stack(&mut self) {
self.stack.clear()
}
pub fn push(&mut self, value: Value<'gc>) { pub fn push(&mut self, value: Value<'gc>) {
avm_debug!(self, "Stack push {}: {value:?}", self.stack.len()); avm_debug!(self, "Stack push {}: {value:?}", self.stack.len());
self.stack.push(value); self.stack.push(value);

View File

@ -1661,6 +1661,10 @@ impl Player {
} }
} }
} }
// AVM1 bytecode may leave the stack unbalanced, so do not let garbage values accumulate
// across multiple executions and/or frames.
context.avm1.clear_stack();
} }
} }