---
title: "CWE-772: Missing Release of Resource after Effective Lifetime"
url: https://radicalnotion.ai/cwe/cwe-772
type: cwe
description: "The product does not release a resource after its effective lifetime has ended, i.e., after the resource is no longer needed."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-772: Missing Release of Resource after Effective Lifetime

- **Abstraction:** Base
- **Structure:** Simple
- **Status:** Draft
- **Likelihood of exploit:** High
- **CVEs with this as primary weakness:** 1,168
- **Of those, in CISA KEV:** 1
- **New in 2026:** 583
- **CWE catalog version:** 4.21

## Description

The product does not release a resource after its effective lifetime has ended, i.e., after the resource is no longer needed.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | - |

## Applicable platforms

**Technologies:** Mobile (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Availability | DoS: Resource Consumption (Other), DoS: Resource Consumption (Memory), DoS: Resource Consumption (CPU) | An attacker that can influence the allocation of resources that are not properly released could deplete the available resource pool and prevent all other processes from accessing the same type of resource. Frequently-affected resources include memory, CPU, disk space, power or battery, etc. |

## Potential mitigations

### Requirements (Language Selection)

Use a language that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid.

For example, languages such as Java, Ruby, and Lisp perform automatic garbage collection that releases memory for objects that have been deallocated.

### Implementation

It is good practice to be responsible for freeing all resources you allocate and to be consistent with how and where you free resources in a function. If you allocate resources that you intend to free upon completion of the function, you must be sure to free the resources at all exit points for that function including error conditions.

### Operation, Architecture and Design (Resource Limitation)

Use resource-limiting settings provided by the operating system or environment. For example, when managing system resources in POSIX, setrlimit() can be used to set limits for certain types of resources, and getrlimit() can determine how many resources are available. However, these functions are not available on all operating systems.

When the current levels get close to the maximum that is defined for the application (see CWE-770), then limit the allocation of further resources to privileged users; alternately, begin releasing resources for less-privileged users. While this mitigation may protect the system from attack, it will not necessarily stop attackers from adversely impacting other users.

Ensure that the application performs the appropriate error checks and error handling in case resources become unavailable (CWE-703).

## Detection methods

### Automated Static Analysis

Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

Effectiveness: High

## Demonstrative examples

### Example 1

The following method never closes the new file handle. Given enough time, the Finalize() method for BufferReader should eventually call Close(), but there is no guarantee as to how long this action will take. In fact, there is no guarantee that Finalize() will ever be invoked. In a busy environment, the Operating System could use up all of the available file handles before the Close() function is called.

Bad code:

```java
private void processFile(string fName)
{
    BufferReader fil = new BufferReader(new FileReader(fName));
    String line;
    while ((line = fil.ReadLine()) != null)
    {
        processLine(line);
    }
}
```

Good code:

```java
private void processFile(string fName)
{
    BufferReader fil = new BufferReader(new FileReader(fName));
    String line;
    while ((line = fil.ReadLine()) != null)
    {
        processLine(line);
    }
    fil.Close();
}
```

The good code example simply adds an explicit call to the Close() function when the system is done using the file. Within a simple example such as this the problem is easy to see and fix. In a real system, the problem may be considerably more obscure.

### Example 2

The following code attempts to open a new connection to a database, process the results returned by the database, and close the allocated SqlConnection object.

Bad code:

```c#
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand(queryString);
cmd.Connection = conn;
conn.Open();
SqlDataReader rdr = cmd.ExecuteReader();
HarvestResults(rdr);
conn.Connection.Close();
```

The problem with the above code is that if an exception occurs while executing the SQL or processing the results, the SqlConnection object is not closed. If this happens often enough, the database will run out of available cursors and not be able to execute any more SQL queries.

### Example 3

This code attempts to open a connection to a database and catches any exceptions that may occur.

Bad code:

```java
try {
    Connection con = DriverManager.getConnection(some_connection_string);
}
catch ( Exception e ) {
    log( e );
}
```

If an exception occurs after establishing the database connection and before the same connection closes, the pool of database connections may become exhausted. If the number of available connections is exceeded, other users cannot access this resource, effectively denying access to the application.

### Example 4

Under normal conditions the following C# code executes a database query, processes the results returned by the database, and closes the allocated SqlConnection object. But if an exception occurs while executing the SQL or processing the results, the SqlConnection object is not closed. If this happens often enough, the database will run out of available cursors and not be able to execute any more SQL queries.

Bad code:

```c#
...
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand(queryString);
cmd.Connection = conn;
conn.Open();
SqlDataReader rdr = cmd.ExecuteReader();
HarvestResults(rdr);
conn.Connection.Close();
...
```

### Example 5

The following C function does not close the file handle it opens if an error occurs. If the process is long-lived, the process can run out of file handles.

Bad code:

```c
int decodeFile(char* fName) {
    char buf[BUF_SZ];
    FILE* f = fopen(fName, "r");
    if (!f) {
        printf("cannot open %s\n", fName);
        return DECODE_FAIL;
    }
    else {
        while (fgets(buf, BUF_SZ, f)) {
            if (!checkChecksum(buf)) {
                return DECODE_FAIL;
            }
            else {
                decodeBlock(buf);
            }
        }
    }
    fclose(f);
    return DECODE_SUCCESS;
}
```

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2007-0897 | Chain: anti-virus product encounters a malformed file but returns from a function without closing a file descriptor (CWE-775) leading to file descriptor consumption (CWE-400) and failed scans. |
| CVE-2001-0830 | Sockets not properly closed when attacker repeatedly connects and disconnects from server. |
| CVE-1999-1127 | Does not shut down named pipe connections if malformed data is sent. |
| CVE-2009-2858 | Chain: memory leak (CWE-404) leads to resource exhaustion. |
| CVE-2009-2054 | Product allows exhaustion of file descriptors when processing a large number of TCP packets. |
| CVE-2008-2122 | Port scan triggers CPU consumption with processes that attempt to read data from closed sockets. |
| CVE-2007-4103 | Product allows resource exhaustion via a large number of calls that do not complete a 3-way handshake. |
| CVE-2002-1372 | Chain: Return values of file/socket operations are not checked (CWE-252), allowing resultant consumption of file descriptors (CWE-772). |

## Real CVEs with this weakness (sample of 12 of 1,168)

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2024-20481 | Cisco Adaptive Security Appliance and Firepower Threat Defense Software Remote Access VPN Brute Force Denial of Service Vulnerability | medium | 5.8 | - | Yes | 2024-10-23 |
| CVE-2026-74279 | crypto: cavium/cpt - fix DMA cleanup using wrong loop index | critical | 10.0 | - | No | 2026-08-15 |
| CVE-2026-72493 | net: serialize netif\_running() check in enqueue\_to\_backlog() | critical | 9.9 | - | No | 2026-08-15 |
| CVE-2026-98352 | RDMA/rtrs-clt: Fix CQ pool leak when connect is interrupted | critical | 9.8 | - | No | 2026-10-06 |
| CVE-2026-98351 | wifi: virt\_wifi: free skb when disconnected | critical | 9.8 | - | No | 2026-10-06 |
| CVE-2026-98327 | wifi: mac80211: mesh: reset the CSA state when leaving | critical | 9.8 | - | No | 2026-10-06 |
| CVE-2026-98326 | wifi: mac80211: mesh: release the channel if start fails | critical | 9.8 | - | No | 2026-10-06 |
| CVE-2026-98321 | netfilter: nf\_nat: unregister and release hooks on error | critical | 9.8 | - | No | 2026-10-06 |
| CVE-2026-98319 | drm: Fix drm\_pending\_vblank\_event leak in error path for out\_fence\_ptr | critical | 9.8 | - | No | 2026-10-06 |
| CVE-2026-98289 | af\_unix: Unify scc\_index when finalising SCC in \_\_unix\_walk\_scc(). | critical | 9.8 | - | No | 2026-10-06 |
| CVE-2026-98233 | net/packet: clear RX owner on VNET header error | critical | 9.8 | - | No | 2026-10-06 |
| CVE-2026-98179 | drm/amdgpu: fix rmmio iounmap skipped on device removal | critical | 9.8 | - | No | 2026-10-06 |

## Related attack patterns (CAPEC)

- [CAPEC-469](https://radicalnotion.ai/capec/capec-469): HTTP DoS

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-404](https://radicalnotion.ai/cwe/cwe-404) | Improper Resource Shutdown or Release |
| Child | [CWE-401](https://radicalnotion.ai/cwe/cwe-401) | Missing Release of Memory after Effective Lifetime |
| Child | [CWE-775](https://radicalnotion.ai/cwe/cwe-775) | Missing Release of File Descriptor or Handle after Effective Lifetime |
| Child | [CWE-1091](https://radicalnotion.ai/cwe/cwe-1091) | Use of Object without Invoking Destructor Method |
| Related | [CWE-911](https://radicalnotion.ai/cwe/cwe-911) | Improper Update of Reference Count |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| CERT C Secure Coding | Close files when they are no longer needed | FIO42-C | CWE More Abstract |
| CERT C Secure Coding | Free dynamically allocated memory when no longer needed | MEM31-C | CWE More Abstract |
| OMG ASCSM | - | ASCSM-CWE-772 | - |
| OMG ASCRM | - | ASCRM-CWE-772 | - |
| Software Fault Patterns | Failure to Release Resource | SFP14 | - |

## Frequently asked questions

### What is CWE-772?

The product does not release a resource after its effective lifetime has ended, i.e., after the resource is no longer needed.

### What CVEs are caused by CWE-772?

1,168 recorded CVEs are attributed to CWE-772, including CVE-2024-20481, CVE-2026-74279 and CVE-2026-72493. 1 is listed in CISA's Known Exploited Vulnerabilities (KEV) catalog.

### How do you prevent CWE-772?

Use a language that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid.

### How is CWE-772 detected?

Automated Static Analysis: Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

### What are the consequences of CWE-772?

Exploiting CWE-772 can lead to: DoS: Resource Consumption (Other), DoS: Resource Consumption (Memory), DoS: Resource Consumption (CPU).

### Is CWE-772 actively exploited?

Yes. 1 CWE-772 vulnerability is in CISA's KEV catalog of actively exploited flaws, out of 1,168 recorded CVEs.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/772.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-772). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
