diff --git a/src/Bytecode/Instruction/execute.c b/src/Bytecode/Instruction/execute.c index 9917b84..c64d09a 100644 --- a/src/Bytecode/Instruction/execute.c +++ b/src/Bytecode/Instruction/execute.c @@ -729,6 +729,11 @@ struct GroundExecutionResult _GroundBytecodeInstructionExecute(GroundBytecodeIns Ground.Log.Error("malloc failed in Ground.Bytecode.Instruction.execute"); Ground.Flags.error = true; return CONTINUE; + } else { + // forget all values in previous closure + for (GroundSize i = 0; i < function->closure->len; i++) { + Ground.Free.BytecodeValue(&function->closure->heap[i]); + } } for (GroundSize i = 0; i < heap->len; i++) { @@ -785,6 +790,12 @@ struct GroundExecutionResult _GroundBytecodeInstructionExecute(GroundBytecodeIns // And store the result HEAP_SET(heap, instruction->args.at[instruction->args.len - 1], result); + // Clean up the new heap + for (GroundSize i = 0; i < newHeap.len; i++) { + Ground.Free.BytecodeValue(&newHeap.heap[i]); + } + free(newHeap.heap); + return CONTINUE; } CALLMETHOD: {