The standard C library provides fopen and the system call open to open and possibly create files. Each call to one of
these functions must be matched with a respective call to fclose or close.
Failing to close files that have been opened may lead to using up all of the OS’s file handles.
What is the potential impact?
If a program does not properly close or release file handles after using them, it will leak resources. In that case, the program will continue to
hold onto file handles even when they are no longer needed, eventually exhausting the available file handles.
If a program has run out of file handles and tries to open yet another file, the file opening operation will fail. This can result in errors or
unexpected behavior in the program.
The program may not be able to read or write to files anymore, which can cause data loss, corruption, or incomplete operations. In some cases, when
a program runs out of file handles, it may crash or hang indefinitely. This can happen if the program does not handle the error condition properly or
if it enters an infinite loop trying to open files, for instance. In the worst case, a resource leak can lock up everything that runs on the
machine.