diff options
author | mrb0nk500 <b0nk@b0nk.xyz> | 2020-06-13 08:53:02 -0400 |
---|---|---|
committer | mrb0nk500 <b0nk@b0nk.xyz> | 2020-06-13 08:53:02 -0400 |
commit | 9ed46f16faad3300876c3ab40aab1660ef8c4a08 (patch) | |
tree | 40179552da5dc732f872d273e5f343482efacde9 | |
parent | 460832c13c9d476d71e626a0c42de4eeff3feb63 (diff) |
Fixed some bugs with freeing the linked lists.
Thanks to BieHDC for pointing this out to me.
-rw-r--r-- | assemble.c | 34 |
1 files changed, 13 insertions, 21 deletions
@@ -359,10 +359,11 @@ void assemble(line *ln, bytecount *bc, uint8_t dbg) { } } -static inline void free_tokens(token *t, uint16_t count) { +static inline void free_tokens(token *t) { token *tok; - for (; t != NULL && t >= tok; t = t->next) { + while (t != NULL) { tok = t; + t = t->next; free(tok); } } @@ -370,32 +371,22 @@ static inline void free_tokens(token *t, uint16_t count) { void free_lines() { line *l = lines; line *ln; - for (; l != NULL && l >= ln; l = l->next) { - free_tokens(l->tok, l->count); + while (l != NULL) { + free_tokens(l->tok); ln = l; + l = l->next; free(ln); } } -void free_locals(symbol *s) { +void free_symbols(symbol *s) { symbol *sym; - for (; s != NULL && s >= sym; s = s->next) { - sym = s; - if (sym->name != NULL) { - free(sym->name); - } - free(sym); - } -} - -void free_symbols() { - symbol *s = symbols; - symbol *sym = symbols; - for (; s != NULL && s >= sym; s = s->next) { + while (s != NULL) { if (s->local) { - free_locals(s->local); + free_symbols(s->local); } sym = s; + s = s->next; if (sym->name != NULL) { free(sym->name); } @@ -406,8 +397,9 @@ void free_symbols() { static inline void free_fixups() { fixup *f = fixups; fixup *fix; - for (; f != NULL && f >= fix; f = f->next) { + while (f != NULL) { fix = f; + f = f->next; free(fix); } } @@ -418,7 +410,7 @@ void cleanup() { free_lines(); } if (symbols) { - free_symbols(); + free_symbols(symbols); } if (fixups) { free_fixups(); |