libc -- dmalloc: Call malloc_init as-needed, rather than via cc constructor.
authorVenkatesh Srinivas <me@endeavour.zapto.org>
Sun, 20 May 2012 14:10:56 +0000 (07:10 -0700)
committerVenkatesh Srinivas <me@endeavour.zapto.org>
Sun, 20 May 2012 14:10:56 +0000 (07:10 -0700)
commite12d3396c777165504d60d2a1408dcd7cb63660d
tree034c038b15082c96124caf1a22d81fd27d68a17f
parent7a7e10d6267ef12bf6e84d69a9e77fec14d6dccb
libc -- dmalloc: Call malloc_init as-needed, rather than via cc constructor.

dmalloc requires its own _nmalloc_thr_init be called before it can service
allocations. Applications with preinit arrays were able to call malloc before
constructors ran, which caused them to crash on uninitialized allocator state.

The change uses a flag to test for allocator init state. It is also careful
to not allow _nmalloc_thr_init to be called recursively from within pthread
initialization (slglobal.masked).

Reported-by: marino@
Closes-bug: 2305
lib/libc/stdlib/dmalloc.c