Safeguard
Application Security•

CWE-771 Missing Reference to Active Allocated Resource

Lose the last reference to a resource that needs explicit cleanup and it can never be reclaimed. Learn how this drains pools and how to keep control.

Safeguard Security Team
2 min read

CWE-771 describes a product that does not properly maintain a reference to a resource it has allocated, which prevents the resource from being reclaimed. Think of a handle that was created, dropped on the floor, and can no longer be returned.

MITRE notes this does not necessarily apply in languages or frameworks that garbage collect, because removing all references can signal that a resource is ready for reclaiming. It matters most where cleanup is manual.

How it happens

A function allocates a resource, stores the only pointer in a local variable, and returns or overwrites it. The resource still exists, but nothing knows where it is. Repeat that in a loop and the pool shrinks with every pass.

What an attacker gains

The recorded consequence is availability. An attacker who can influence these allocations can deplete the available resource pool and stop other processes from getting the same type of resource.

How to find it

Static analysis can find some instances by tracing data flow from allocation to release. Run long soak tests as well, and watch resource counts such as memory, handles and connections. A count that only climbs points at a leak.

How to fix it

  1. Make one owner responsible for each resource and keep a reference until it is released.
  2. Apply the resource limits your operating system or environment offers. On POSIX, MITRE names setrlimit() and getrlimit() for this.
  3. Handle the failure case. Check for errors when resources become unavailable instead of assuming allocation always works.

Limits will not stop an attacker from hurting other users of the same service, but they protect the rest of the system.

Quick check

Does a garbage collected language remove this risk?

Mostly for memory, since dropped references allow reclaiming. Resources like sockets and files can still need explicit release.

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.