...
This noncompliant code example defines a function that is called before the program exits to clean up.:
Code Block | ||||
---|---|---|---|---|
| ||||
void cleanup(void) { /* Delete temporary files, restore consistent state, etc. */ } int main(void) { if (atexit(cleanup) != 0) { /* Handle error */ } /* ... */ assert(/* something bad didn't happen */); /* ... */ } |
...
In this compliant solution, the call to assert()
is replaced with an if
statement that calls exit()
to ensure that the proper termination routines are run.:
Code Block | ||||
---|---|---|---|---|
| ||||
void cleanup(void) { /* Delete temporary files, restore consistent state, etc */ } int main(void) { if (atexit(cleanup) != 0) { /* Handle error */ } /* ... */ if (/* something bad happened */) { exit(EXIT_FAILURE); } /* ... */ } |
...
Tool | Version | Checker | Description |
---|---|---|---|
Compass/ROSE |
|
| Can detect some violations of this rule. However, it can only detect violations involving |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
...