Our malloc()
implementation is actually async signal safe, by way of deferring signal delivery. I suspect the issue in this case is rather that malloc()
isn't fork()
safe in an multi-threaded program. If one thread calls fork()
while another is currently in malloc()
(or free()
,...) the child process will inherit a locked mutex.
The solution is to register respective atfork()
hooks for the memory allocator. They would acquire the mutex pre-fork()
and release it post-fork()
, thus ensuring that the child finds the memory allocator in a usable state.