fix init race that could lead to deadlock in malloc init code
authorRich Felker <dalias@aerifal.cx>
Wed, 4 Mar 2015 14:29:39 +0000 (09:29 -0500)
committerRich Felker <dalias@aerifal.cx>
Wed, 4 Mar 2015 14:29:39 +0000 (09:29 -0500)
commit7a81fe3710be0128d29071e76c5acbea3d84277b
tree1ba3a7b2433dc4671a5b516996ee9051044cc622
parent56fbaa3bbe73f12af2bfbbcf2adb196e6f9fe264
fix init race that could lead to deadlock in malloc init code

the malloc init code provided its own version of pthread_once type
logic, including the exact same bug that was fixed in pthread_once in
commit 0d0c2f40344640a2a6942dda156509593f51db5d.

since this code is called adjacent to expand_heap, which takes a lock,
there is no reason to have pthread_once-type initialization. simply
moving the init code into the interval where expand_heap already holds
its lock on the brk achieves the same result with much less
synchronization logic, and allows the buggy code to be eliminated
rather than just fixed.
src/malloc/malloc.c