Not safe to use SystemStats::getStackBacktrace from the crash handler

/** Sets up a global callback function that will be called if the application
executes some kind of illegal instruction.
You may want to call getStackBacktrace() in your handler function, to find out
where the problem happened and log it, etc.
static void setApplicationCrashHandler (CrashHandlerFunction);

actually juce's posix implementation of SystemStats::getStackBacktrace makes use of backtrace_symbols which:

The backtrace_symbols() function translates the numerical program counter values previously recorded by a call to backtrace() in the buffer argument, and converts, where possible, each PC to a string indicating the module, function and offset of each call site. The number of symbols present in the array must be passed in with the size argument.

The set of strings is returned in an array obtained from a call to malloc(3C). It is the responsibility of the caller to pass the returned pointer to free(). The individual strings must not be freed. Since malloc() is used to obtain the needed space, this function is MT-Safe rather than Async-Signal-Safe and cannot be used reliably from a signal handler. This function is provided for glibc compatibility.

it's safer to use backtrace_symbols_fd which doesn't malloc and rely only on write which can be used safely from within a signal handler.


Ok, ta for the heads-up. (After adding this function I actually didn't end up using it anywhere myself so didn't run into any problems)

I’m bumping this since I see @jules didn’t use it. however if it’s there, wouldn’t it be better to get it fixed? at least with latest tip I still see it uses backtrace_symbols rather than suggested backtrace_symbols_fd