Weakness · Medium
CWE-404: Improper Resource Shutdown or Release
What it is
The product does not release or incorrectly releases a resource before it is made available for re-use.
- Severity (our rating)
- Medium
- Likelihood of exploit
- Medium
- Introduced during
- Implementation
- Exploited in the wild
- 6 known exploited CVEs
In more detail
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.
What an attacker can do
- DoS: Resource Consumption (Other) (Availability, Other)
- Varies by Context (Availability, Other)
- Read Application Data (Confidentiality)
How to prevent it
Requirements
- 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.
- Memory should be allocated/freed using matching functions such as malloc/free, new/delete, and new[]/delete[].
- When releasing a complex object or structure, ensure that you properly dispose of all of its member components, not just the object itself.
How to find it
- 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.
- 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.)
Exploited in the wild: 6 CVEs
Vulnerabilities caused by CWE-404 that attackers have used, from CISA's Known Exploited Vulnerabilities catalog, newest first.
- CVE-2018-8639 ransomwareMicrosoft Windows Win32k Improper Resource Shutdown or Release Vulnerability · added March 3, 2025
- CVE-2018-8611Microsoft Windows Kernel Privilege Escalation Vulnerability · added May 24, 2022
- CVE-2018-8406 ransomwareMicrosoft DirectX Graphics Kernel Privilege Escalation Vulnerability · added March 28, 2022
- CVE-2018-8405 ransomwareMicrosoft DirectX Graphics Kernel Privilege Escalation Vulnerability · added March 28, 2022
- CVE-2018-8120 ransomwareMicrosoft Win32k Privilege Escalation Vulnerability · added March 15, 2022
- CVE-2018-8453 ransomwareMicrosoft Win32k Privilege Escalation Vulnerability · added January 21, 2022
H2 Security
Found it in your code?
We review where it appears, fix it with your team, and check it was not already used against you.
Talk to our teamT Academy
Stop writing it in the first place
Learn to build software and systems without weaknesses like this one, with practice on real hosts in your browser, every objective checked on the machine.
Start freeSource: MITRE Common Weakness Enumeration, CWE version 4.19.1. CWE is a trademark of The MITRE Corporation.