Corrects all known memory leaks

This commit is contained in:
Sage Vaillancourt 2021-07-05 05:08:37 -04:00
parent c7d3d7f457
commit d4d1f27a63
2 changed files with 9 additions and 4 deletions

View File

@ -64,8 +64,9 @@ struct Environment envForLambda(const Object *params, const Object *arg_forms,
for(int i = 0; i < paramCount; i++) {
const char *newObjName = itemAt(params, i)->string;
// Eval the `march` list
const Object newEnvObj = eval(march, outer);
Object newEnvObj = eval(march, outer);
addToEnv(&env, newObjName, newEnvObj); // Could use eval_forms?
cleanObject(&newEnvObj);
march = march->forward;
}

View File

@ -45,9 +45,12 @@ Object evalDefArgs(const Object *symbol, const Object *value, struct Environment
Object evalIfArgs(const Object *argForms, struct Environment *env)
{
return eval(argForms, env).number ?
Object condition = eval(argForms, env);
Object result = condition.number ?
eval(argForms->forward, env) :
eval(argForms->forward->forward, env);
cleanObject(&condition);
return result;
}
Object evalLambdaArgs(const Object *argForms)
@ -242,7 +245,7 @@ Object evalList(const Object *obj, struct Environment *env)
if(listLength(obj->list) == 0) {
return cloneObject(*obj);
}
return startList(cloneObject(eval(obj->list, env)));
return startList(eval(obj->list, env));
}
Object *first_form = obj->list;
@ -735,7 +738,8 @@ Object parseEval(const char *input, struct Environment *env)
cleanObject(&obj);
Object parsed = parse(tok).obj;
if(parsed.type == TYPE_ERROR) {
return parsed;
obj = parsed;
break;
}
if(tok[i].text[0] == ')') {
tok = &tok[i + 1];