CERT-SIG30-C
In this section:
Synopsis
Call only asynchronous-safe functions within signal handlers
Enabled by default
Yes
Severity/Certainty
High/High

Full description
Program behavior is undefined if the signal handler calls any function in the standard library that is not asynchronous-safe.
Coding standards
- CERT SIG30-C
Call only asynchronous-safe functions within signal handlers
Code examples
The following code example fails the check and will give a warning:
#include <signal.h>
#include <stdlib.h>
void handler(int signum) {
int *x = malloc(sizeof(int));
}
void example(void) {
signal(SIGINT, handler);
}
The following code example passes the check and will not give a warning about this issue:
#include <signal.h>
void foo(void) {
_exit();
}
void handler(int signum) {
foo();
}
void example(void) {
signal(SIGINT, handler);
}