[git commit branch/0.9.33] libc: atexit: reuse free slots at the end of exit functions table
Carmelo Amoroso
carmelo.amoroso at st.com
Tue Feb 5 15:00:43 UTC 2013
commit: http://git.uclibc.org/uClibc/commit/?id=893d4fb45bb0811bcc939054e60e37a47a1786c5
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/0.9.33
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 at raritan.com>
Tested-by: Filippo Arcidiacono <filippo.arcidiacono at st.com>
Signed-off-by: Carmelo Amoroso <carmelo.amoroso at st.com>
(cherry picked from commit 389cd96704f21549cafc0b5bdcd0ef762b98bc08)
---
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 48b97ff..0af8c57 100644
--- a/libc/stdlib/_atexit.c
+++ b/libc/stdlib/_atexit.c
@@ -240,6 +240,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) {
More information about the uClibc-cvs
mailing list