From b4cbced5f5c63f44ed6823938e2460d54b9c289d Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Sat, 4 Jul 2026 13:27:50 +1000 Subject: [PATCH] Clean up after function call --- src/Bytecode/Instruction/execute.c | 11 +++++++++++ 1 file changed, 11 insertions(+) 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: {