From c8dabe7abc07f8c05fb445c38f85d6fb4d2bcadd Mon Sep 17 00:00:00 2001 From: Augusto Gunsch Date: Sat, 21 Nov 2020 10:44:52 -0300 Subject: [PATCH] Fix memory leaks --- assembler.c | 10 ++++++++++ main.c | 1 + parser.h | 1 + 3 files changed, 12 insertions(+) diff --git a/assembler.c b/assembler.c index 7130315..182f4ae 100644 --- a/assembler.c +++ b/assembler.c @@ -238,6 +238,7 @@ void striplabels(ASSEMBLER* a) { a->lns = curln->next; LINELIST* tmp = curln; curln = curln->next; + free(tmp->content); free(tmp); } else { @@ -372,8 +373,17 @@ void translate(ASSEMBLER* a) { } } +void freelns(LINELIST* lns) { + LINELIST* next = lns->next; + free(lns->content); + free(lns); + if(next != NULL) + freelns(next); +} + void freeassembler(ASSEMBLER* a) { freesymbols(a->vars); freesymbols(a->labels); + freelns(a->lns); free(a); } diff --git a/main.c b/main.c index 0e38d45..381bf42 100644 --- a/main.c +++ b/main.c @@ -35,6 +35,7 @@ int main(int argc, char* argv[]) { parse(p); ASSEMBLER* a = mkassembler(p->output); + free(p); // variable substitution preprocess(a); diff --git a/parser.h b/parser.h index d7d8a9a..3f5676d 100644 --- a/parser.h +++ b/parser.h @@ -15,4 +15,5 @@ typedef struct { PARSER* mkparser(FILE* input); void parse(PARSER* p); +void freeparser(PARSER* p); #endif