Safeguard
Application Security•

CWE-773 Missing Reference to Active File Descriptor or Handle

When code loses track of an open file descriptor it can never close it, and the process slowly runs out. Learn how it happens and how to cap the damage.

Safeguard Security Team
2 min read

CWE-773 is the file descriptor flavor of lost references. The product does not properly maintain references to a file descriptor or handle, which prevents it from being reclaimed.

Servers that open many files or sockets feel this first, because a leak that costs one descriptor per request adds up fast.

How it happens

Code opens a file or socket and then overwrites the variable holding it, or returns early without passing it on. The descriptor stays open in the process, but no code path can close it.

What an attacker gains

Availability, per the record. The product can consume all available file descriptors or handles, which prevents other processes from doing critical file work. An attacker who can trigger the leaking path repeatedly turns a slow leak into an outage.

How to find it

MITRE says static analysis can find some instances. Dynamic checks are simpler: watch the open descriptor count of a running process under load. On Linux, listing the process's open files before and after a batch of requests shows a leak clearly.

How to fix it

  1. Keep a reference to every descriptor until it is closed, and close it on every path, including errors.
  2. Use the limits your platform gives you. MITRE names setrlimit() and getrlimit() on POSIX systems.
  3. When usage nears the cap, restrict further allocation to privileged users, or start releasing descriptors held for less privileged ones.
  4. Check for failure when a descriptor cannot be allocated.

Quick check

What is the quickest symptom of a descriptor leak?

The process's open descriptor count rises with traffic and never falls back, until opens start failing.

Sources

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.