---
title: "CWE-404: Improper Resource Shutdown or Release"
url: https://radicalnotion.ai/cwe/cwe-404
type: cwe
description: "The product does not release or incorrectly releases a resource before it is made available for re-use."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-404: Improper Resource Shutdown or Release

- **Abstraction:** Class
- **Structure:** Simple
- **Status:** Draft
- **Likelihood of exploit:** Medium
- **CVEs with this as primary weakness:** 637
- **Of those, in CISA KEV:** 5
- **New in 2026:** 180
- **CWE catalog version:** 4.21

## Description

The product does not release or incorrectly releases a resource before it is made available for re-use.

When a resource is created or allocated, the developer is responsible for properly releasing the resource as well as accounting for all potential paths of expiration or invalidation, such as a set period of time or revocation.

## Modes of introduction

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

## Applicable platforms

**Languages:** Python (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Availability, Other | DoS: Resource Consumption (Other), Varies by Context | Most unreleased resource issues result in general software reliability problems, but if an attacker can intentionally trigger a resource leak, the attacker might be able to launch a denial of service attack by depleting the resource pool. |
| Confidentiality | Read Application Data | When a resource containing sensitive information is not correctly shutdown, it may expose the sensitive data in a subsequent allocation. |

## 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 memory in a function. If you allocate memory that you intend to free upon completion of the function, you must be sure to free the memory at all exit points for that function including error conditions.

### Implementation

Memory should be allocated/freed using matching functions such as malloc/free, new/delete, and new\[\]/delete\[\].

### Implementation

When releasing a complex object or structure, ensure that you properly dispose of all of its member components, not just the object itself.

## Detection methods

### Automated Dynamic Analysis

This weakness can be detected using dynamic tools and techniques that interact with the software using large test suites with many diverse inputs, such as fuzz testing (fuzzing), robustness testing, and fault injection. The software's operation may slow down, but it should not become unstable, crash, or generate incorrect results.

Resource clean up errors might be detected with a stress-test by calling the software simultaneously from a large number of threads or processes, and look for evidence of any unexpected behavior. The software's operation may slow down, but it should not become unstable, crash, or generate incorrect results.

Effectiveness: Moderate

### Manual Dynamic Analysis

Identify error conditions that are not likely to occur during normal usage and trigger them. For example, run the product under low memory conditions, run with insufficient privileges or permissions, interrupt a transaction before it is completed, or disable connectivity to basic network services such as DNS. Monitor the software for any unexpected behavior. If you trigger an unhandled exception or similar error that was discovered and handled by the application's environment, it may still indicate unexpected conditions that were not handled by the application itself.

### 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

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 3

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 4

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;
}
```

### Example 5

In this example, the program does not use matching functions such as malloc/free, new/delete, and new\[\]/delete\[\] to allocate/deallocate the resource.

Bad code:

```c++
class A {
    void foo();
};
void A::foo(){
    int *ptr;
    ptr = (int*)malloc(sizeof(int));
    delete ptr;
}
```

### Example 6

In this example, the program calls the delete\[\] function on non-heap memory.

Bad code:

```c++
class A{
    void foo(bool);
};
void A::foo(bool heap) {
    int localArray[2] = {
        11,22
    };
    int *p = localArray;
    if (heap){
        p = new int[2];
    }
    delete[] p;
}
```

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-1999-1127 | Does not shut down named pipe connections if malformed data is sent. |
| CVE-2001-0830 | Sockets not properly closed when attacker repeatedly connects and disconnects from server. |
| 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 637)

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2018-8639 | Microsoft Windows Win32k Improper Resource Shutdown or Release Vulnerability | high | 8.6 | - | Yes | 2018-12-12 |
| CVE-2018-8611 | Microsoft Windows Kernel Privilege Escalation Vulnerability | high | 8.5 | - | Yes | 2018-12-12 |
| CVE-2018-8405 | Microsoft DirectX Graphics Kernel Privilege Escalation Vulnerability | high | 8.5 | - | Yes | 2018-08-15 |
| CVE-2018-8406 | Microsoft DirectX Graphics Kernel Privilege Escalation Vulnerability | high | 8.5 | - | Yes | 2018-08-15 |
| CVE-2018-8120 | Microsoft Win32k Privilege Escalation Vulnerability | high | 7.3 | - | Yes | 2018-05-09 |
| CVE-2026-68161 | sctp: close UDP tunnel sockets during netns teardown | critical | 9.8 | - | No | 2026-08-10 |
| CVE-2023-24444 | Session fixation vulnerability in Jenkins OpenID Plugin | critical | 9.8 | - | No | 2023-01-24 |
| CVE-2024-31611 | - | critical | 9.1 | - | No | 2024-06-10 |
| CVE-2026-68091 | HID: wacom: stop hardware after post-start probe failures | high | 8.8 | - | No | 2026-08-10 |
| CVE-2018-8450 | Windows Search Remote Code Execution Vulnerability | high | 8.8 | - | No | 2018-11-14 |
| CVE-2018-8282 | Microsoft Windows Child Window NULL Pointer Dereference Privilege Escalation Vulnerability | high | 8.8 | - | No | 2018-07-11 |
| CVE-2026-112082 | sgl-project SGLang Expert-Distribution Recording Endpoint expert\_distribution.py Scheduler.expert\_distribution\_handle denial of service | high | 8.7 | - | No | 2026-10-19 |

## Related attack patterns (CAPEC)

- [CAPEC-125](https://radicalnotion.ai/capec/capec-125): Flooding
- [CAPEC-130](https://radicalnotion.ai/capec/capec-130): Excessive Allocation
- [CAPEC-131](https://radicalnotion.ai/capec/capec-131): Resource Leak Exposure
- [CAPEC-494](https://radicalnotion.ai/capec/capec-494): TCP Fragmentation
- [CAPEC-495](https://radicalnotion.ai/capec/capec-495): UDP Fragmentation
- [CAPEC-496](https://radicalnotion.ai/capec/capec-496): ICMP Fragmentation
- [CAPEC-666](https://radicalnotion.ai/capec/capec-666): BlueSmacking

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-664](https://radicalnotion.ai/cwe/cwe-664) | Improper Control of a Resource Through its Lifetime |
| Child | [CWE-299](https://radicalnotion.ai/cwe/cwe-299) | Improper Check for Certificate Revocation |
| Child | [CWE-401](https://radicalnotion.ai/cwe/cwe-401) | Missing Release of Memory after Effective Lifetime |
| Child | [CWE-459](https://radicalnotion.ai/cwe/cwe-459) | Incomplete Cleanup |
| Child | [CWE-761](https://radicalnotion.ai/cwe/cwe-761) | Free of Pointer not at Start of Buffer |
| Child | [CWE-762](https://radicalnotion.ai/cwe/cwe-762) | Mismatched Memory Management Routines |
| Child | [CWE-763](https://radicalnotion.ai/cwe/cwe-763) | Release of Invalid Pointer or Reference |
| Child | [CWE-772](https://radicalnotion.ai/cwe/cwe-772) | Missing Release of Resource after Effective Lifetime |
| Child | [CWE-775](https://radicalnotion.ai/cwe/cwe-775) | Missing Release of File Descriptor or Handle after Effective Lifetime |
| Peer | [CWE-239](https://radicalnotion.ai/cwe/cwe-239) | Failure to Handle Incomplete Element |
| Peer | [CWE-405](https://radicalnotion.ai/cwe/cwe-405) | Asymmetric Resource Consumption (Amplification) |
| Can precede | [CWE-619](https://radicalnotion.ai/cwe/cwe-619) | Dangling Database Cursor |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| PLOVER | Improper resource shutdown or release | - | - |
| 7 Pernicious Kingdoms | Unreleased Resource | - | - |
| OWASP Top Ten 2004 | Denial of Service | A9 | CWE More Specific |
| 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 |
| The CERT Oracle Secure Coding Standard for Java (2011) | Release resources when they are no longer needed | FIO04-J | - |
| Software Fault Patterns | Failure to release resource | SFP14 | - |
| OpenSSF Secure Coding Guide for Python | Release Unused Resources | pyscg-0051 | - |

## Frequently asked questions

### What is CWE-404?

The product does not release or incorrectly releases a resource before it is made available for re-use.

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

637 recorded CVEs are attributed to CWE-404, including CVE-2018-8639, CVE-2018-8611 and CVE-2018-8405. 5 are listed in CISA's Known Exploited Vulnerabilities (KEV) catalog.

### Is CWE-404 part of the OWASP Top 10?

CWE-404 maps to OWASP Top Ten 2004: Denial of Service (A9) in the OWASP security taxonomy.

### How do you prevent CWE-404?

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

### How is CWE-404 detected?

Automated Dynamic Analysis: This weakness can be detected using dynamic tools and techniques that interact with the software using large test suites with many diverse inputs, such as fuzz testing (fuzzing), robustness testing, and fault injection. The software's operation may slow down, but it should not become unstable, crash, or generate incorrect results.

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

Exploiting CWE-404 can lead to: DoS: Resource Consumption (Other), Varies by Context, Read Application Data.

### Is CWE-404 actively exploited?

Yes. 5 CWE-404 vulnerabilities are in CISA's KEV catalog of actively exploited flaws, out of 637 recorded CVEs.

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

---

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