Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Failing to close files when they are no longer needed may allow attackers to exhaust, and possibly manipulate, system resources. This phenomenon is typically referred to as file descriptor leakage, although file pointers may also be used as an attack vector. To prevent file descriptor leaks, files should be closed when they are no longer needed.

Be careful not to close the standard streams (especially stdout), because if the application is piping into another the second application may detect EOF and take actions that shouldn't have occurred until the first application terminates.

Non-Compliant Code Example

...