--- /dev/null
+Submitted By: Jonathan Norman (jonathan at bluesquarelinux dot co dot uk)
+Date: 2012-02-16
+Initial Package Version: 2.15
+Origin: http://sourceware.org/ml/libc-alpha/2011-06/msg00010.html
+Upstream Status: Submitted
+Description: Fixes segfault with sound devices / output.
+
+diff -Naur eglibc-2_15.orig/elf/dl-close.c eglibc-2_15/elf/dl-close.c
+--- eglibc-2_15.orig/elf/dl-close.c 2012-02-16 09:31:47.478224779 +0000
++++ eglibc-2_15/elf/dl-close.c 2012-02-16 09:37:17.287098571 +0000
+@@ -119,17 +119,8 @@
+ if (map->l_direct_opencount > 0 || map->l_type != lt_loaded
+ || dl_close_state != not_pending)
+ {
+- if (map->l_direct_opencount == 0)
+- {
+- if (map->l_type == lt_loaded)
+- dl_close_state = rerun;
+- else if (map->l_type == lt_library)
+- {
+- struct link_map **oldp = map->l_initfini;
+- map->l_initfini = map->l_orig_initfini;
+- _dl_scope_free (oldp);
+- }
+- }
++ if (map->l_direct_opencount == 0 && map->l_type == lt_loaded)
++ dl_close_state = rerun;
+
+ /* There are still references to this object. Do nothing more. */
+ if (__builtin_expect (GLRO_dl_debug_mask & DL_DEBUG_FILES, 0))
+diff -Naur eglibc-2_15.orig/elf/dl-deps.c eglibc-2_15/elf/dl-deps.c
+--- eglibc-2_15.orig/elf/dl-deps.c 2012-02-16 09:31:47.474224671 +0000
++++ eglibc-2_15/elf/dl-deps.c 2012-02-16 09:39:54.791335897 +0000
+@@ -489,6 +489,8 @@
+ nneeded * sizeof needed[0]);
+ atomic_write_barrier ();
+ l->l_initfini = l_initfini;
++ l->l_free_initfini = 1;
++
+ }
+
+ /* If we have no auxiliary objects just go on to the next map. */
+@@ -689,6 +691,7 @@
+ l_initfini[nlist] = NULL;
+ atomic_write_barrier ();
+ map->l_initfini = l_initfini;
++ map->l_free_initfini = 1;
+ if (l_reldeps != NULL)
+ {
+ atomic_write_barrier ();
+@@ -697,7 +700,7 @@
+ _dl_scope_free (old_l_reldeps);
+ }
+ if (old_l_initfini != NULL)
+- map->l_orig_initfini = old_l_initfini;
++ _dl_scope_free (old_l_initfini);
+
+ if (errno_reason)
+ _dl_signal_error (errno_reason == -1 ? 0 : errno_reason, objname,
+diff -Naur eglibc-2_15.orig/elf/dl-libc.c eglibc-2_15/elf/dl-libc.c
+--- eglibc-2_15.orig/elf/dl-libc.c 2012-02-16 09:31:47.478224779 +0000
++++ eglibc-2_15/elf/dl-libc.c 2012-02-16 09:32:43.619735410 +0000
+@@ -284,6 +284,10 @@
+ if (! old->dont_free)
+ free (old);
+ }
++
++ /* Free the initfini dependency list. */
++ if (l->l_free_initfini)
++ free (l->l_initfini);
+ }
+
+ if (__builtin_expect (GL(dl_ns)[ns]._ns_global_scope_alloc, 0) != 0
+diff -Naur eglibc-2_15.orig/elf/rtld.c eglibc-2_15/elf/rtld.c
+--- eglibc-2_15.orig/elf/rtld.c 2012-02-16 09:31:47.470224563 +0000
++++ eglibc-2_15/elf/rtld.c 2012-02-16 09:35:01.611448263 +0000
+@@ -2277,6 +2277,7 @@
+ lnp->dont_free = 1;
+ lnp = lnp->next;
+ }
++ l->l_free_initfini = 0;
+
+ if (l != &GL(dl_rtld_map))
+ _dl_relocate_object (l, l->l_scope, GLRO(dl_lazy) ? RTLD_LAZY : 0,
+diff -Naur eglibc-2_15.orig/include/link.h eglibc-2_15/include/link.h
+--- eglibc-2_15.orig/include/link.h 2012-02-16 09:31:47.710231021 +0000
++++ eglibc-2_15/include/link.h 2012-02-16 09:42:04.610828212 +0000
+@@ -192,6 +192,9 @@
+ during LD_TRACE_PRELINKING=1
+ contains any DT_SYMBOLIC
+ libraries. */
++ unsigned int l_free_initfini:1; /* Nonzero if l_initfini can be
++ freed, ie. not allocated with
++ the dummy malloc in ld.so. */
+
+ /* Collected information about own RPATH directories. */
+ struct r_search_path_struct l_rpath_dirs;
+@@ -240,9 +243,6 @@
+
+ /* List of object in order of the init and fini calls. */
+ struct link_map **l_initfini;
+- /* The init and fini list generated at startup, saved when the
+- object is also loaded dynamically. */
+- struct link_map **l_orig_initfini;
+
+ /* List of the dependencies introduced through symbol binding. */
+ struct link_map_reldeps