Fix memory issues

This commit is contained in:
2025-12-01 10:36:09 +11:00
parent 6eeccf58fe
commit 995c1d984b
3 changed files with 53 additions and 20 deletions

View File

@@ -95,7 +95,7 @@ void addVariable(GroundVariable **head, const char *id, GroundValue data) {
}
GroundVariable* item = malloc(sizeof(GroundVariable));
snprintf(item->id, MAX_ID_LEN, "%s", id);
item->value = data;
item->value = copyGroundValue(&data);
HASH_ADD_STR(*head, id, item);
}
@@ -129,7 +129,7 @@ void interpretGroundInstruction(GroundInstruction inst, GroundScope* scope) {
GroundVariable* variable = findVariable(*scope->variables, in->args.args[i].value.refName);
if (variable) {
free(in->args.args[i].value.refName); // Free the strdup'd refName
in->args.args[i].value.value = variable->value;
in->args.args[i].value.value = copyGroundValue(&variable->value);
in->args.args[i].type = VALUE;
} else {
runtimeError(UNKNOWN_VARIABLE, NULL, in, currentInstruction);