CWE-772: Missing Release of Resource after Effective Lifetime
The product does not release a resource after its effective lifetime has ended, i.e., after the resource is no longer needed.
View on MITRETechnical Details
- Structure
- Simple
Applicable To
Security Consequences
Scope
Impact
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.
Mitigation Strategies
Phase
Description
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.
Detection Methods
No detection method information available for this CWE.
Code Examples & CVEs
Demonstrative Examples
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.
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.
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.
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.
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.
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.
This code attempts to open a connection to a database and catches any exceptions that may occur.
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.
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.
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.
Observed CVE Examples (8)
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.
View DetailsSockets not properly closed when attacker repeatedly connects and disconnects from server.
View DetailsProduct allows exhaustion of file descriptors when processing a large number of TCP packets.
View DetailsPort scan triggers CPU consumption with processes that attempt to read data from closed sockets.
View DetailsProduct allows resource exhaustion via a large number of calls that do not complete a 3-way handshake.
View DetailsChain: Return values of file/socket operations are not checked (CWE-252), allowing resultant consumption of file descriptors (CWE-772).
View DetailsCWE Relationships
Frequently Asked Questions
What is CWE-772: Missing Release of Resource after Effective Lifetime?+
CWE-772: Missing Release of Resource after Effective Lifetime is a Common Weakness Enumeration (CWE) entry maintained by MITRE. The product does not release a resource after its effective lifetime has ended, i.e., after the resource is no longer needed.
What are the security consequences of Missing Release of Resource after Effective Lifetime?+
If exploited, CWE-772 (Missing Release of Resource after Effective Lifetime) it can compromise Availability, leading to outcomes such as DoS: Resource Consumption (Other), DoS: Resource Consumption (Memory) and DoS: Resource Consumption (CPU).
How do you prevent or mitigate Missing Release of Resource after Effective Lifetime?+
Recommended mitigations for CWE-772 include: 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.
What are real-world examples of Missing Release of Resource after Effective Lifetime?+
MITRE documents real CVEs mapped to CWE-772, including CVE-2007-0897, CVE-2001-0830, CVE-1999-1127, CVE-2009-2858 and CVE-2009-2054. You can look up the full details of each CVE, including CVSS scores and remediation guidance, on our CVE Lookup tool.
What is the difference between a CWE and a CVE?+
A CWE (Common Weakness Enumeration) like CWE-772 describes a category of software weakness — the underlying flaw type. A CVE (Common Vulnerabilities and Exposures) identifies a specific, real-world vulnerability in a particular product. In short, a CWE is the kind of mistake, and a CVE is an instance of that mistake being found in software.