From 13a7ad97b57d94c56946d7ced99db61c12e3a2b1 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Thu, 17 Mar 2022 13:23:19 -0400 Subject: [PATCH] Correct known memory leaks. --- src/env.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) 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); }