Why can’t malloc be used in signal handlers? What can “happen wrong”?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A signal handler can be called at any time, including during times when another call to
mallocis in progress. If this happens, one of two things will occur:mallocwill be unable to acquire the heap lock.mallocdoes acquire the lock (or doesn’t think it needs it), then proceeds to render the heap inconsistent, leading to a later crash.