Fix memory leaks

This commit is contained in:
Augusto Gunsch 2020-11-21 10:44:52 -03:00
parent e456ace07b
commit c8dabe7abc
No known key found for this signature in database
GPG Key ID: F7EEFE29825C72DC
3 changed files with 12 additions and 0 deletions

View File

@ -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);
}

1
main.c
View File

@ -35,6 +35,7 @@ int main(int argc, char* argv[]) {
parse(p);
ASSEMBLER* a = mkassembler(p->output);
free(p);
// variable substitution
preprocess(a);

View File

@ -15,4 +15,5 @@ typedef struct {
PARSER* mkparser(FILE* input);
void parse(PARSER* p);
void freeparser(PARSER* p);
#endif