A call to the ``++fopen()++``/``++open()++`` function must be matched with a call to ``++fclose()++``/``++close++``. Otherwise, you run the risk of using up all the OS's file handles, which could lock up not just your program but potentially everything on the box.

== Noncompliant Code Example

----
int fun() {
  FILE *f = fopen("file", "r");
  if (f == NULL) {
    return -1;
  }
  // ...
  return 0; // Noncompliant, file f has not been closed
}
----

== Compliant Solution

----
int fun() {
  FILE *f = fopen("file", "r");
  if (f == NULL) {
    return -1;
  }
  // ...
  fclose(f);
  return 0;
}
----

include::../see.adoc[]

ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)

include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]
