diff --git a/src/env.c b/src/env.c index f46432d..2f74ce6 100644 --- a/src/env.c +++ b/src/env.c @@ -195,6 +195,14 @@ void deleteEnv(struct Environment* e) if (e->outer) { deleteEnv(e->outer); } + + for (int i = 0; i < e->structCount; i++) { + free(e->structDefs[i].name); + for (int j = 0; j < e->structDefs[i].fieldCount; j++) { + free(e->structDefs[j].names); + } + } + if (e->strings) { int i = 0; while (e->strings[i]) { @@ -208,6 +216,7 @@ void deleteEnv(struct Environment* e) free(e->objects); e->objects = NULL; } + free(e->structDefs); } struct symFunc { diff --git a/src/object.c b/src/object.c index 232a8ae..4ebfd0f 100644 --- a/src/object.c +++ b/src/object.c @@ -541,8 +541,8 @@ void cleanObject(Object* target) break; case TYPE_ERROR: #ifndef SIMPLE_ERRORS - //free(target->error->context); - //free(target->error); + free(target->error->context); + free(target->error); target->error = NULL; #endif break; diff --git a/src/pebblisp.c b/src/pebblisp.c index 4c0ae19..9f950fc 100644 --- a/src/pebblisp.c +++ b/src/pebblisp.c @@ -70,9 +70,9 @@ Object evalStructArgs(const Object* symbol, const Object* fields, struct Environ } struct StructDef def; - //def.name = name; def.name = malloc(sizeof(char) * (strlen(name) + 1)); strcpy(def.name, name); + def.fieldCount = listLength(fields); def.names = malloc(sizeof(char*) * def.fieldCount); @@ -88,7 +88,6 @@ Object evalStructArgs(const Object* symbol, const Object* fields, struct Environ } env->structDefs[env->structCount] = def; - //printStructDef(&env->structDefs[env->structCount]); env->structCount += 1; if (env->structCount == env->structCapacity) { struct StructDef* prev = env->structDefs; @@ -96,8 +95,6 @@ Object evalStructArgs(const Object* symbol, const Object* fields, struct Environ env->structCapacity *= 2; env->structDefs = malloc(sizeof(struct StructDef) * env->structCapacity); printf("Can malloc\n"); - //memcpy(env->structDefs, prev, sizeof(struct StructDef) * prevCapacity); - //printf("Can memcpy\n"); for (int i = 0; i < prevCapacity; i++) { env->structDefs[i] = prev[i]; } @@ -319,7 +316,6 @@ Object evalList(const Object* obj, struct Environment* env) cleanObject(&builtIn); } - //struct StructDef *def = NULL; int def = -1; if (first_form->type == TYPE_SYMBOL) { struct Environment* outerEnv = env; @@ -423,7 +419,7 @@ Object reduce(const Object listInitial, const Object func, struct Environment* e //Object oldTotal = total; total = eval(&funcList, env); //cleanObject(&oldTotal); - //cleanObject(&funcList); + cleanObject(&funcList); //cleanObject(¤t); }