Skip to main content

IAR Embedded Workbench for Arm 9.70.x

RESOURCE-double-close

In this section:
Synopsis

A file resource is closed multiple times

Enabled by default

Yes

Severity/Certainty

High/Medium

highmedium.png
Full description

An open file is closed multiple times without being re-opened in between. This will cause an application crash. This check is identical to CERT-FIO46-C_c.

Coding standards
CERT FIO46-C

Do not access a closed file

CWE 672

Operation on a Resource after Expiration or Release

Code examples

The following code example fails the check and will give a warning:

#include <stdio.h>

void example(void) {
  FILE *f1;
  f1 = fopen("test_file", "w");
  fclose(f1);
  fclose(f1);
} 

The following code example passes the check and will not give a warning about this issue:

#include <stdio.h>

void example(void) {
  FILE *f1;
  f1 = fopen("test_file", "w");
  fclose(f1);
}