fix le memory leak

This commit is contained in:
2026-06-16 20:01:42 +10:00
parent 9539629cfb
commit 02b5a9cc54
6 changed files with 73 additions and 5 deletions

10
src/Free/Arg.c Normal file
View File

@@ -0,0 +1,10 @@
#include "../../include/ground.h"
void _GroundFreeArg(GroundArg* in) {
if (in->type == GroundArg_Value) {
Ground.Free.Value(&in->as.value);
} else {
// FIXME - double free for arg
// free(in->as.ref);
}
}

10
src/Free/Instruction.c Normal file
View File

@@ -0,0 +1,10 @@
#include "../../include/ground.h"
void _GroundFreeInstruction(GroundInstruction* in) {
for (size_t i = 0; i < in->args.len; i++) {
Ground.Free.Arg(&in->args.at[i]);
}
free(in->args.at);
in->args.len = 0;
in->args.capacity = 0;
}

10
src/Free/Program.c Normal file
View File

@@ -0,0 +1,10 @@
#include "../../include/ground.h"
void _GroundFreeProgram(GroundProgram* in) {
for (size_t i = 0; i < in->len; i++) {
Ground.Free.Instruction(&in->at[i]);
}
free(in->at);
in->len = 0;
in->capacity = 0;
}

26
src/Free/State.c Normal file
View File

@@ -0,0 +1,26 @@
#include "../../include/ground.h"
void _GroundFreeState(GroundState* in) {
{
GroundVariable *s, *tmp;
HASH_ITER(hh, in->variables, s, tmp) {
Ground.Free.Value(&s->value);
HASH_DEL(in->variables, s);
free(s);
}
}
{
GroundCatch *s, *tmp;
HASH_ITER(hh, in->catches, s, tmp) {
HASH_DEL(in->variables, s);
free(s);
}
}
{
GroundLabel *s, *tmp;
HASH_ITER(hh, in->labels, s, tmp) {
HASH_DEL(in->variables, s);
free(s);
}
}
}