[PATCH] malloc: Perform full initialization before __malloc_check_init

Wilco Dijkstra Wilco.Dijkstra@arm.com
Thu Sep 21 18:15:00 GMT 2017


Florian Weimer wrote:

Well it looks like the malloc initialization is insane. It sets default hooks for 
malloc/realloc/etc which call ptmalloc_init, which is completely unguarded
from multi-threaded execution... Then it implicitly relies on have_fastchunks
being true (from zero-initialization of main_arena by inverting the meaning of
the flag), which should eventually result in a call to malloc_consolidate, which
assuming max_fast hasn't yet been set, finally calls malloc_init_state...

+    {
+      /* Perform full initialization.  */
+      malloc_consolidate (&main_arena);
+      __malloc_check_init ();
+    }

That's an improvement but ptmalloc_init should call malloc_init_state (&main_arena)
in all cases. The check in malloc_consolidate should then be removed (no idea why
anyone would want to delay initialization to that point...). Interestingly malloc_init_state
is called for other arenas...

Wilco



More information about the Libc-alpha mailing list