...
A nested call to an exit function is undefined behavior. (See undefined behavior 182187.) This behavior can occur only when an exit function is invoked from an exit handler or when an exit function is called from within a signal handler. (See SIG30-C. Call only asynchronous-safe functions within signal handlers.)
If a call to the longjmp() function is made that would terminate the call to a function registered with atexit(), the behavior is undefined behavior 187.
Noncompliant Code Example
In this noncompliant code example, the exit1() and exit2() functions are registered by atexit() to perform required cleanup upon program termination. However, if some_condition evaluates to true, exit() is called a second time, resulting in undefined behavior 187.
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <stdlib.h>
void exit1(void) {
/* ... Cleanup code ... */
return;
}
void exit2(void) {
extern int some_condition;
if (some_condition) {
/* ... More cleanup code ... */
exit(0);
}
return;
}
int main(void) {
if (atexit(exit1) != 0) {
/* Handle error */
}
if (atexit(exit2) != 0) {
/* Handle error */
}
/* ... Program code ... */
return 0;
}
|
...