MISRAC2012-Rule-22.1_b
In this section:
Synopsis
(Required) All resources obtained dynamically by means of Standard Library functions shall be explicitly released
Enabled by default
Yes
Severity/Certainty
Medium/Medium

Full description
A file pointer is never closed. This check is identical to MISRAC2012-Dir-4.13_c, 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
- CWE 404
Improper Resource Shutdown or Release
- MISRA C:2012 Rule-22.1
(Required) All resources obtained dynamically by means of Standard Library functions shall be explicitly released
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);
}