The cirros image was rebuilt against the 3.13.0-83 kernel, drivers e1000e, igbvf...
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / buildroot-2015.05 / package / uclibc / 0.9.33.2 / 0039-libc-atexit-reuse-free-slots-at-the-end-of-exit-func.patch
1 From 893d4fb45bb0811bcc939054e60e37a47a1786c5 Mon Sep 17 00:00:00 2001
2 From: Ronald Wahl <ronald.wahl@raritan.com>
3 Date: Mon, 4 Feb 2013 14:51:46 +0100
4 Subject: [PATCH] libc: atexit: reuse free slots at the end of exit functions
5  table
6
7 Continuosly dlopen and dlclose of shared object will cause a memory leak
8 in atexit function. This fix reuse free slots at the end of the list.
9
10 For further detail see https://bugs.busybox.net/show_bug.cgi?id=2455
11
12 Signed-off-by: Ronald Wahl <ronald.wahl@raritan.com>
13 Tested-by: Filippo Arcidiacono <filippo.arcidiacono@st.com>
14 Signed-off-by: Carmelo Amoroso <carmelo.amoroso@st.com>
15 (cherry picked from commit 389cd96704f21549cafc0b5bdcd0ef762b98bc08)
16 ---
17  libc/stdlib/_atexit.c |   10 ++++++++++
18  1 file changed, 10 insertions(+)
19
20 diff --git a/libc/stdlib/_atexit.c b/libc/stdlib/_atexit.c
21 index 48b97ff..0af8c57 100644
22 --- a/libc/stdlib/_atexit.c
23 +++ b/libc/stdlib/_atexit.c
24 @@ -240,6 +240,16 @@ struct exit_function attribute_hidden *__new_exitfn(void)
25  
26      __UCLIBC_MUTEX_LOCK(__atexit_lock);
27  
28 +       /*
29 +        * Reuse free slots at the end of the list.
30 +        * This avoids eating memory when dlopen and dlclose modules multiple times.
31 +       */
32 +       while (__exit_count > 0) {
33 +               if (__exit_function_table[__exit_count-1].type == ef_free) {
34 +                       --__exit_count;
35 +               } else break;
36 +       }
37 +
38  #ifdef __UCLIBC_DYNAMIC_ATEXIT__
39      /* If we are out of function table slots, make some more */
40      if (__exit_slots < __exit_count+1) {
41 -- 
42 1.7.10.4
43