release loaded dlls cleanly (Sam K)

This commit is contained in:
grischka
2008-05-05 22:40:49 +00:00
parent 96bd8f2b25
commit f9bf48d643
3 changed files with 24 additions and 9 deletions

13
tcc.c
View File

@ -222,6 +222,7 @@ typedef struct Section {
typedef struct DLLReference {
int level;
void *handle;
char name[1];
} DLLReference;
@ -9486,8 +9487,6 @@ static void preprocess_init(TCCState *s1)
vtop = vstack - 1;
s1->pack_stack[0] = 0;
s1->pack_stack_ptr = s1->pack_stack;
macro_ptr = NULL;
}
/* compile the C file opened in 'file'. Return non zero if errors. */
@ -10095,6 +10094,8 @@ static void tcc_cleanup(void)
cstr_free(&tokcstr);
/* reset symbol stack */
sym_free_first = NULL;
/* cleanup from error/setjmp */
macro_ptr = NULL;
}
TCCState *tcc_new(void)
@ -10227,6 +10228,14 @@ void tcc_delete(TCCState *s1)
for(i = 1; i < s1->nb_sections; i++)
free_section(s1->sections[i]);
tcc_free(s1->sections);
/* free any loaded DLLs */
for ( i = 0; i < s1->nb_loaded_dlls; i++)
{
DLLReference *ref = s1->loaded_dlls[i];
if ( ref->handle )
dlclose(ref->handle);
}
/* free loaded dlls array */
dynarray_reset(&s1->loaded_dlls, &s1->nb_loaded_dlls);