diff options
author | Ronald Wahl <ronald.wahl@raritan.com> | 2013-02-04 14:51:46 +0100 |
---|---|---|
committer | Carmelo Amoroso <carmelo.amoroso@st.com> | 2013-02-05 15:59:18 +0100 |
commit | 389cd96704f21549cafc0b5bdcd0ef762b98bc08 (patch) | |
tree | 1bfa1a3efe9bffc303a99e635e6248476f30a651 /libc | |
parent | 98df9185fdfce0203999edc4d92ac56f38108529 (diff) |
libc: atexit: reuse free slots at the end of exit functions table
Continuosly dlopen and dlclose of shared object will cause a memory leak
in atexit function. This fix reuse free slots at the end of the list.
For further detail see https://bugs.busybox.net/show_bug.cgi?id=2455
Signed-off-by: Ronald Wahl <ronald.wahl@raritan.com>
Tested-by: Filippo Arcidiacono <filippo.arcidiacono@st.com>
Signed-off-by: Carmelo Amoroso <carmelo.amoroso@st.com>
Diffstat (limited to 'libc')
-rw-r--r-- | libc/stdlib/_atexit.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/libc/stdlib/_atexit.c b/libc/stdlib/_atexit.c index 4bb884075..ef6772fb5 100644 --- a/libc/stdlib/_atexit.c +++ b/libc/stdlib/_atexit.c @@ -241,6 +241,16 @@ struct exit_function attribute_hidden *__new_exitfn(void) __UCLIBC_MUTEX_LOCK(__atexit_lock); + /* + * Reuse free slots at the end of the list. + * This avoids eating memory when dlopen and dlclose modules multiple times. + */ + while (__exit_count > 0) { + if (__exit_function_table[__exit_count-1].type == ef_free) { + --__exit_count; + } else break; + } + #ifdef __UCLIBC_DYNAMIC_ATEXIT__ /* If we are out of function table slots, make some more */ if (__exit_slots < __exit_count+1) { |