--- tcc.c 2009/03/18 14:24:41 1.5 +++ tcc.c 2009/03/20 10:46:47 1.6 @@ -1301,14 +1301,21 @@ return sec; } -static void free_section(Section *s) +static void free_private_section(Section *s) { - if (s->link && (s->link->sh_flags & SHF_PRIVATE)) - free_section(s->link); - if (s->hash && (s->hash->sh_flags & SHF_PRIVATE)) - s->hash->link = NULL, free_section(s->hash); - tcc_free(s->data); - tcc_free(s); + if (s->link && (s->link->sh_flags & SHF_PRIVATE)) { + free_private_section(s->link); + s->link = 0; + } + if (s->hash && (s->hash->sh_flags & SHF_PRIVATE)) { + s->hash->link = NULL; + free_private_section(s->hash); + s->hash = 0; + } + if (s->sh_flags & SHF_PRIVATE) { + tcc_free(s->data); + tcc_free(s); + } } /* realloc section and set its content to zero */ @@ -10437,10 +10444,15 @@ tcc_cleanup(); /* free all sections */ - free_section(s1->dynsymtab_section); + free_private_section(s1->dynsymtab_section); for(i = 1; i < s1->nb_sections; i++) - free_section(s1->sections[i]); + free_private_section(s1->sections[i]); + for(i = 1; i < s1->nb_sections; i++) { + tcc_free(s1->sections[i]->data); + tcc_free(s1->sections[i]); + } + tcc_free(s1->sections); /* free any loaded DLLs */