Fix minor memory leaks

This commit is contained in:
Augusto Gunsch 2020-12-31 20:41:22 -03:00
parent b880e97990
commit e89b0696d7
No known key found for this signature in database
GPG Key ID: F7EEFE29825C72DC
3 changed files with 14 additions and 2 deletions

View File

@ -50,7 +50,9 @@ LINE* mathopln(char op) {
LINE* pushconstant(int n) { LINE* pushconstant(int n) {
char* tokens[] = { "push", "constant", itoa(n) }; char* tokens[] = { "push", "constant", itoa(n) };
return mkln(tokens); LINE* ln = mkln(tokens);
free(tokens[2]);
return ln;
} }
LINE* pushthat() { LINE* pushthat() {

View File

@ -92,8 +92,12 @@ LINEBLOCK* compileif(COMPILER* c, SCOPE* s, IFSTATEMENT* st) {
blk = mergelnblks(blk, compilestatements(c, s, st->elsestatements)); blk = mergelnblks(blk, compilestatements(c, s, st->elsestatements));
char* endlabelln[] = { "label", endlabel }; char* endlabelln[] = { "label", endlabel };
appendln(blk, mkln(endlabelln)); appendln(blk, mkln(endlabelln));
free(endlabel);
} }
free(falselabel);
free(truelabel);
return blk; return blk;
} }
@ -124,6 +128,9 @@ LINEBLOCK* compilewhile(COMPILER* c, SCOPE* s, CONDSTATEMENT* w) {
char* endlabelln[] = { "label", endlabel }; char* endlabelln[] = { "label", endlabel };
appendln(blk, mkln(endlabelln)); appendln(blk, mkln(endlabelln));
free(explabel);
free(endlabel);
return blk; return blk;
} }

View File

@ -1,8 +1,11 @@
#include <stdlib.h>
#include "compiler-util.h" #include "compiler-util.h"
LINE* opvarraw(SCOPE* s, char* op, VAR* v) { LINE* opvarraw(SCOPE* s, char* op, VAR* v) {
char* tokens[] = { op, v->memsegment, itoa(v->index) }; 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) { LINE* opvar(SCOPE* s, char* op, const char* name) {