MISRAC2012-Dir-4.13_c
Synopsis
(Advisory) Functions which are designed to provide operations on a resource should be called in an approriate sequence. One or more file pointers are never closed. To avoid failure caused by resource exhaustion, all file pointers obtained dynamically by means of Standard Library functions must be explicitly released. Releasing them as soon as possible reduces the risk that exhaustion will occur.
Enabled by default
No
Severity/Certainty
High/Medium

Full description
A file pointer is never closed. This check is identical to MISRAC2012-Rule-22.1_b, RESOURCE-file-no-close-all, SEC-FILEOP-open-no-close, CERT-FIO42-C_a.
Coding standards
- CERT FIO42-C
Ensure files are properly closed when they are no longer needed
- MISRA C:2012 Dir-4.13
(Advisory) Functions which are designed to provide operations on a resource should be called in an appropriate sequence
Code examples
The following code example fails the check and will give a warning:
#include <stdio.h>
void example(void) {
FILE *fp = fopen("test.txt", "c");
}
The following code example passes the check and will not give a warning about this issue:
#include <stdio.h>
void example(void) {
FILE *fp = fopen("test.txt", "c");
fclose(fp);
}