Clean up after function call

This commit is contained in:
2026-07-04 13:27:50 +10:00
parent 396a6d9a1b
commit b4cbced5f5

View File

@@ -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: {