[glibc] malloc: Fix malloc init order

Wilco Dijkstra wilco@sourceware.org
Tue May 27 15:37:54 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=919bf1489abe634aefbcf3532617e7c5987c56ab

commit 919bf1489abe634aefbcf3532617e7c5987c56ab
Author: Wilco Dijkstra <wilco.dijkstra@arm.com>
Date:   Tue May 27 13:32:45 2025 +0000

    malloc: Fix malloc init order
    
    __ptmalloc_init was called too early in __libc_early_init: it uses
    __libc_initial which is not set yet.  Fix this by moving initialization
    to the end of __libc_early_init.
    
    Reviewed-by: Florian Weimer <fweimer@redhat.com>

Diff:
---
 elf/libc_early_init.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/elf/libc_early_init.c b/elf/libc_early_init.c
index 24b99d82fe..4da170a7ca 100644
--- a/elf/libc_early_init.c
+++ b/elf/libc_early_init.c
@@ -33,9 +33,6 @@ _Bool __libc_initial;
 void
 __libc_early_init (_Bool initial)
 {
-  /* Initialize system malloc.  */
-  call_function_static_weak (__ptmalloc_init);
-
   /* Initialize ctype data.  */
   __ctype_init ();
 
@@ -53,4 +50,7 @@ __libc_early_init (_Bool initial)
 #if ENABLE_ELISION_SUPPORT
   __lll_elision_init ();
 #endif
+
+  /* Initialize system malloc (needs __libc_initial to be set).  */
+  call_function_static_weak (__ptmalloc_init);
 }


More information about the Glibc-cvs mailing list