From e89b0696d72c5f67603c7fabe7a8119762f5a1a8 Mon Sep 17 00:00:00 2001 From: Augusto Gunsch Date: Thu, 31 Dec 2020 20:41:22 -0300 Subject: [PATCH] Fix minor memory leaks --- compiler/compiler-expressions.c | 4 +++- compiler/compiler-statements.c | 7 +++++++ compiler/compiler-util.c | 5 ++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/compiler/compiler-expressions.c b/compiler/compiler-expressions.c index b96ec7a..ef45988 100644 --- a/compiler/compiler-expressions.c +++ b/compiler/compiler-expressions.c @@ -50,7 +50,9 @@ LINE* mathopln(char op) { LINE* pushconstant(int n) { char* tokens[] = { "push", "constant", itoa(n) }; - return mkln(tokens); + LINE* ln = mkln(tokens); + free(tokens[2]); + return ln; } LINE* pushthat() { diff --git a/compiler/compiler-statements.c b/compiler/compiler-statements.c index 3af3bce..bb50253 100644 --- a/compiler/compiler-statements.c +++ b/compiler/compiler-statements.c @@ -92,8 +92,12 @@ LINEBLOCK* compileif(COMPILER* c, SCOPE* s, IFSTATEMENT* st) { blk = mergelnblks(blk, compilestatements(c, s, st->elsestatements)); char* endlabelln[] = { "label", endlabel }; appendln(blk, mkln(endlabelln)); + free(endlabel); } + free(falselabel); + free(truelabel); + return blk; } @@ -124,6 +128,9 @@ LINEBLOCK* compilewhile(COMPILER* c, SCOPE* s, CONDSTATEMENT* w) { char* endlabelln[] = { "label", endlabel }; appendln(blk, mkln(endlabelln)); + free(explabel); + free(endlabel); + return blk; } diff --git a/compiler/compiler-util.c b/compiler/compiler-util.c index 9b44059..a699e3d 100644 --- a/compiler/compiler-util.c +++ b/compiler/compiler-util.c @@ -1,8 +1,11 @@ +#include #include "compiler-util.h" LINE* opvarraw(SCOPE* s, char* op, VAR* v) { char* tokens[] = { op, v->memsegment, itoa(v->index) }; - return mksimpleln(tokens, strcount(tokens)); + LINE* ln = mksimpleln(tokens, strcount(tokens)); + free(tokens[2]); + return ln; } LINE* opvar(SCOPE* s, char* op, const char* name) {