From 684e63a87801ebc34432c331c9c8b7730ecd9f54 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Thu, 6 Sep 2018 19:43:18 -0400 Subject: [PATCH] handle pthread_atfork calling into malloc This results in compatibility with the malloc replacement support added in musl 1.1.20. --- malloc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/malloc.c b/malloc.c index 8492fa4..5d58692 100644 --- a/malloc.c +++ b/malloc.c @@ -609,10 +609,6 @@ COLD static void init_slow_path(void) { return; } - if (pthread_atfork(full_lock, full_unlock, post_fork_child)) { - fatal_error("pthread_atfork failed"); - } - if (sysconf(_SC_PAGESIZE) != PAGE_SIZE) { fatal_error("page size mismatch"); } @@ -673,6 +669,11 @@ COLD static void init_slow_path(void) { } pthread_mutex_unlock(&mutex); + + // may allocate, so wait until the allocator is initialized to avoid deadlocking + if (pthread_atfork(full_lock, full_unlock, post_fork_child)) { + fatal_error("pthread_atfork failed"); + } } static inline void init(void) {