diff --git a/src/env.c b/src/env.c index 2f74ce6..6b05c1a 100644 --- a/src/env.c +++ b/src/env.c @@ -74,9 +74,8 @@ struct Environment envForLambda(const Object* params, const Object* arg_forms, march = march->forward; } - while(outer) { + if(outer) { outer->refs += 1; - outer = outer->outer; } return env; } @@ -196,13 +195,6 @@ void deleteEnv(struct Environment* e) 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]) { @@ -212,10 +204,17 @@ void deleteEnv(struct Environment* e) } free(e->strings); e->strings = NULL; - free(e->objects); e->objects = NULL; } + + 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[i].names[j]); + } + free(e->structDefs[i].names); + } free(e->structDefs); }