This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] malloc: Fix ptmalloc_lock_all/_int_new_arena deadlock [BZ #19182]


This is just a minimal change.  The fork handler lock acquisition has to
go away anyway if we make fork async-signal-safe (bug 4737).
2015-11-03  Florian Weimer  <fweimer@redhat.com>

	[BZ #19182]
	* malloc/arena.c (_int_new_arena): Do not acquire arena lock while
	list_lock is acquired.

diff --git a/malloc/arena.c b/malloc/arena.c
index 0f00afa..161902c 100644
--- a/malloc/arena.c
+++ b/malloc/arena.c
@@ -785,25 +785,26 @@ _int_new_arena (size_t size)
   set_head (top (a), (((char *) h + h->size) - ptr) | PREV_INUSE);
 
   LIBC_PROBE (memory_arena_new, 2, a, size);
   mstate replaced_arena = thread_arena;
   thread_arena = a;
   mutex_init (&a->mutex);
-  (void) mutex_lock (&a->mutex);
 
   (void) mutex_lock (&list_lock);
 
   detach_arena (replaced_arena);
 
   /* Add the new arena to the global list.  */
   a->next = main_arena.next;
   atomic_write_barrier ();
   main_arena.next = a;
 
   (void) mutex_unlock (&list_lock);
 
+  (void) mutex_lock (&a->mutex);
+
   return a;
 }
 
 
 static mstate
 get_free_list (void)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]