scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 7b77d09eb9716ebb472547635cf8b2dba0908103
parent ffe766e4bd6d01ff1a8498e63cffca21ca50eab9
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 24 Apr 2014 15:30:03 +0200

Fix symbol deletion

When we free a symbol it is the head of the list, so the head is
no longer valid, and it is needed update the head to the next
element in the list.

Diffstat:
symbol.c | 5+++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/symbol.c b/symbol.c @@ -31,13 +31,14 @@ void freesyms(uint8_t ns) { static struct symtab *tbl; - register Symbol *sym; + register Symbol *sym, *next; tbl = &symtab[(ns >= NR_NAMESPACES) ? NS_IDEN : ns]; - for (sym = tbl->head; sym; sym = sym->next) { + for (sym = tbl->head; sym; sym = next) { if (sym->ctx <= curctx) break; tbl->htab[hash(sym->name)] = sym->hash; + next = tbl->head = sym->next; free(sym->name); free(sym); }