fix le memory leak
This commit is contained in:
10
src/Free/Arg.c
Normal file
10
src/Free/Arg.c
Normal 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
10
src/Free/Instruction.c
Normal 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
10
src/Free/Program.c
Normal 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
26
src/Free/State.c
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,10 @@
|
||||
static inline void doLabels(GroundProgram* program, GroundState* state) {
|
||||
|
||||
for (size_t i = 0; i < program->len; i++) {
|
||||
for (size_t j = 0; j < program->len; j++) {
|
||||
GroundArg* arg = &program->at[i].args.at[j];
|
||||
if (arg->type == GroundArg_Label) {
|
||||
GroundInstruction* instruction = &program->at[i];
|
||||
if (instruction->type == GroundInstruction_CREATELABEL) {
|
||||
if (instruction->args.len > 0) {
|
||||
GroundArg* arg = &instruction->args.at[0];
|
||||
GroundLabel* label = NULL;
|
||||
HASH_FIND_STR(state->labels, arg->as.ref, label);
|
||||
|
||||
@@ -20,6 +21,8 @@ static inline void doLabels(GroundProgram* program, GroundState* state) {
|
||||
Ground.Flags.error = true;
|
||||
return;
|
||||
}
|
||||
strncpy(label->name, arg->as.ref, 2047);
|
||||
label->name[2047] = '\0';
|
||||
label->lineNum = i;
|
||||
HASH_ADD_STR(state->labels, name, label);
|
||||
}
|
||||
@@ -139,8 +142,7 @@ void _GroundInternalRun(GroundProgram* program, GroundState* state) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// TODO: implement
|
||||
// Ground.Free.Instruction(&instruction);
|
||||
Ground.Free.Instruction(&instruction);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,6 +38,11 @@ void _GroundFreeFunction(GroundFunction* in);
|
||||
void _GroundFreeStruct(GroundStruct* in);
|
||||
void _GroundFreeObject(GroundObject* in);
|
||||
|
||||
void _GroundFreeArg(GroundArg* in);
|
||||
void _GroundFreeInstruction(GroundInstruction* in);
|
||||
void _GroundFreeProgram(GroundProgram* in);
|
||||
void _GroundFreeState(GroundState* in);
|
||||
|
||||
|
||||
GroundValue _GroundCopyValue(GroundValue* in);
|
||||
GroundList _GroundCopyList(GroundList* in);
|
||||
@@ -133,6 +138,11 @@ struct _Ground Ground = {
|
||||
.Function = _GroundFreeFunction,
|
||||
.Struct = _GroundFreeStruct,
|
||||
.Object = _GroundFreeObject,
|
||||
|
||||
.Arg = _GroundFreeArg,
|
||||
.Instruction = _GroundFreeInstruction,
|
||||
.Program = _GroundFreeProgram,
|
||||
.State = _GroundFreeState,
|
||||
},
|
||||
|
||||
.Copy = {
|
||||
|
||||
Reference in New Issue
Block a user