CWE

Common Weakness Enumeration

A community-developed list of SW & HW weaknesses that can become vulnerabilities

New to CWE? click here!
CWE Most Important Hardware Weaknesses
CWE Top 25 Most Dangerous Weaknesses
Home > CWE List > CWE-772: Missing Release of Resource after Effective Lifetime (4.20)  
ID

  • Home
  • CWE-772: Missing Release of Resource after Effective Lifetime

    Weakness ID: 772
    Vulnerability Mapping: ALLOWED This CWE ID may be used to map to real-world vulnerabilities
    Abstraction: Base Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource.
    View customized information:
    For users who are interested in more notional aspects of a weakness. Example: educators, technical writers, and project/program managers. For users who are concerned with the practical application and details about the nature of a weakness and how to prevent it from happening. Example: tool developers, security researchers, pen-testers, incident response analysts. For users who are mapping an issue to CWE/CAPEC IDs, i.e., finding the most appropriate CWE for a specific issue (e.g., a CVE record). Example: tool developers, security researchers. For users who wish to see all available information for the CWE/CAPEC entry. For users who want to customize what details are displayed.
    ×

    Edit Custom Filter


    + Description
    The product does not release a resource after its effective lifetime has ended, i.e., after the resource is no longer needed. Diagram for CWE-772
    + Common Consequences
    Section HelpThis table specifies different individual consequences associated with the weakness. The Scope identifies the application security area that is violated, while the Impact describes the negative technical impact that arises if an adversary succeeds in exploiting this weakness. The Likelihood provides information about how likely the specific consequence is expected to be seen relative to the other consequences in the list. For example, there may be high likelihood that a weakness will be exploited to achieve a certain impact, but a low likelihood that it will be exploited to achieve a different impact.
    Impact Details

    DoS: Resource Consumption (Other); DoS: Resource Consumption (Memory); DoS: Resource Consumption (CPU)

    Scope: Availability

    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
    Phase(s) Mitigation

    Requirements

    Strategy: 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

    Strategy: 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).

    + Relationships
    Section Help This table shows the weaknesses and high level categories that are related to this weakness. These relationships are defined as ChildOf, ParentOf, MemberOf and give insight to similar items that may exist at higher and lower levels of abstraction. In addition, relationships such as PeerOf and CanAlsoBe are defined to show similar weaknesses that the user may want to explore.
    + Relevant to the view "Research Concepts" (View-1000)
    Nature Type ID Name
    ChildOf Class Class - a weakness that is described in a very abstract fashion, typically independent of any specific language or technology. More specific than a Pillar Weakness, but more general than a Base Weakness. Class level weaknesses typically describe issues in terms of 1 or 2 of the following dimensions: behavior, property, and resource. 404 Improper Resource Shutdown or Release
    ParentOf Variant Variant - a weakness that is linked to a certain type of product, typically involving a specific language or technology. More specific than a Base weakness. Variant level weaknesses typically describe issues in terms of 3 to 5 of the following dimensions: behavior, property, technology, language, and resource. 401 Missing Release of Memory after Effective Lifetime
    ParentOf Variant Variant - a weakness that is linked to a certain type of product, typically involving a specific language or technology. More specific than a Base weakness. Variant level weaknesses typically describe issues in terms of 3 to 5 of the following dimensions: behavior, property, technology, language, and resource. 775 Missing Release of File Descriptor or Handle after Effective Lifetime
    ParentOf Base Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource. 1091 Use of Object without Invoking Destructor Method
    CanFollow Base Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource. 911 Improper Update of Reference Count
    + Relevant to the view "Software Development" (View-699)
    Nature Type ID Name
    MemberOf Category Category - a CWE entry that contains a set of other entries that share a common characteristic. 399 Resource Management Errors
    + Relevant to the view "Weaknesses for Simplified Mapping of Published Vulnerabilities" (View-1003)
    Nature Type ID Name
    ChildOf Class Class - a weakness that is described in a very abstract fashion, typically independent of any specific language or technology. More specific than a Pillar Weakness, but more general than a Base Weakness. Class level weaknesses typically describe issues in terms of 1 or 2 of the following dimensions: behavior, property, and resource. 404 Improper Resource Shutdown or Release
    + Relevant to the view "CISQ Quality Measures (2020)" (View-1305)
    Nature Type ID Name
    ChildOf Class Class - a weakness that is described in a very abstract fashion, typically independent of any specific language or technology. More specific than a Pillar Weakness, but more general than a Base Weakness. Class level weaknesses typically describe issues in terms of 1 or 2 of the following dimensions: behavior, property, and resource. 404 Improper Resource Shutdown or Release
    + Relevant to the view "CISQ Data Protection Measures" (View-1340)
    Nature Type ID Name
    ChildOf Class Class - a weakness that is described in a very abstract fashion, typically independent of any specific language or technology. More specific than a Pillar Weakness, but more general than a Base Weakness. Class level weaknesses typically describe issues in terms of 1 or 2 of the following dimensions: behavior, property, and resource. 404 Improper Resource Shutdown or Release
    + Modes Of Introduction
    Section HelpThe different Modes of Introduction provide information about how and when this weakness may be introduced. The Phase identifies a point in the life cycle at which introduction may occur, while the Note provides a typical scenario related to introduction during the given phase.
    Phase Note
    Implementation
    + Applicable Platforms
    Section HelpThis listing shows possible areas for which the given weakness could appear. These may be for specific named Languages, Operating Systems, Architectures, Paradigms, Technologies, or a class of such platforms. The platform is listed along with how frequently the given weakness appears for that instance.
    Technologies

    Class: Mobile (Undetermined Prevalence)

    + Likelihood Of Exploit
    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)
    Example Language: Java 
    private void processFile(string fName)
    {
    BufferReader fil = new BufferReader(new FileReader(fName));
    String line;
    while ((line = fil.ReadLine()) != null)
    {
    processLine(line);
    }
    }

    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.

    (good code)
    Example Language: Java 
    private void processFile(string fName)
    {
    BufferReader fil = new BufferReader(new FileReader(fName));
    String line;
    while ((line = fil.ReadLine()) != null)
    {
    processLine(line);
    }
    fil.Close();
    }


    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)
    Example Language: 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)
    Example Language: 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)
    Example Language: 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)
    Example Language:
    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;
    }


    + Selected Observed Examples

    Note: this is a curated list of examples for users to understand the variety of ways in which this weakness can be introduced. It is not a complete list of all CVEs that are related to this CWE entry.

    Reference Description
    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.
    Sockets not properly closed when attacker repeatedly connects and disconnects from server.
    Does not shut down named pipe connections if malformed data is sent.
    Chain: memory leak (CWE-404) leads to resource exhaustion.
    Product allows exhaustion of file descriptors when processing a large number of TCP packets.
    Port scan triggers CPU consumption with processes that attempt to read data from closed sockets.
    Product allows resource exhaustion via a large number of calls that do not complete a 3-way handshake.
    Chain: Return values of file/socket operations are not checked (CWE-252), allowing resultant consumption of file descriptors (CWE-772).
    + Weakness Ordinalities
    Ordinality Description
    Primary
    (where the weakness exists independent of other weaknesses)
    Resultant
    (where the weakness is typically related to the presence of some other weaknesses)
    + Detection Methods
    Method Details

    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

    + Memberships
    Section HelpThis MemberOf Relationships table shows additional CWE Categories and Views that reference this weakness as a member. This information is often useful in understanding where a weakness fits within the context of external information sources.
    Nature Type ID Name
    MemberOf CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. 808 2010 Top 25 - Weaknesses On the Cusp
    MemberOf CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. 867 2011 Top 25 - Weaknesses On the Cusp
    MemberOf CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. 882 CERT C++ Secure Coding Section 14 - Concurrency (CON)
    MemberOf ViewView - a subset of CWE entries that provides a way of examining CWE content. The two main view structures are Slices (flat lists) and Graphs (containing relationships between entries). 884 CWE Cross-section
    MemberOf CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. 982 SFP Secondary Cluster: Failure to Release Resource
    MemberOf CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. 1129 CISQ Quality Measures (2016) - Reliability
    MemberOf CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. 1131 CISQ Quality Measures (2016) - Security
    MemberOf CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. 1162 SEI CERT C Coding Standard - Guidelines 08. Memory Management (MEM)
    MemberOf CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. 1163 SEI CERT C Coding Standard - Guidelines 09. Input Output (FIO)
    MemberOf ViewView - a subset of CWE entries that provides a way of examining CWE content. The two main view structures are Slices (flat lists) and Graphs (containing relationships between entries). 1200 Weaknesses in the 2019 CWE Top 25 Most Dangerous Software Errors
    MemberOf CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. 1416 Comprehensive Categorization: Resource Lifecycle Management
    + Vulnerability Mapping Notes
    Usage ALLOWED
    (this CWE ID may be used to map to real-world vulnerabilities)
    Reason Acceptable-Use

    Rationale

    This CWE entry is at the Base level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities.

    Comments

    Carefully read both the name and description to ensure that this mapping is an appropriate fit. Do not try to 'force' a mapping to a lower-level Base/Variant simply to comply with this preferred level of abstraction.
    + Notes

    Theoretical

    Vulnerability theory is largely about how behaviors and resources interact. "Resource exhaustion" can be regarded as either a consequence or an attack, depending on the perspective. This entry is an attempt to reflect one of the underlying weaknesses that enable these attacks (or consequences) to take place.

    Maintenance

    "Resource exhaustion" (CWE-400) is currently treated as a weakness, although it is more like a category of weaknesses that all have the same type of consequence. While this entry treats CWE-400 as a parent in view 1000, the relationship is probably more appropriately described as a chain.
    + Taxonomy Mappings
    Mapped Taxonomy Name Node ID Fit Mapped Node Name
    CERT C Secure Coding FIO42-C CWE More Abstract Close files when they are no longer needed
    CERT C Secure Coding MEM31-C CWE More Abstract Free dynamically allocated memory when no longer needed
    OMG ASCSM ASCSM-CWE-772
    OMG ASCRM ASCRM-CWE-772
    Software Fault Patterns SFP14 Failure to Release Resource
    + References
    [REF-961] Object Management Group (OMG). "Automated Source Code Reliability Measure (ASCRM)". ASCRM-CWE-772. 2016-01.
    <http://www.omg.org/spec/ASCRM/1.0/>.
    [REF-962] Object Management Group (OMG). "Automated Source Code Security Measure (ASCSM)". ASCSM-CWE-772. 2016-01.
    <http://www.omg.org/spec/ASCSM/1.0/>.
    + Content History
    + Submissions
    Submission Date Submitter Organization
    2009-05-13
    (CWE 1.4, 2009-05-27)
    CWE Content Team MITRE
    + Modifications
    Modification Date Modifier Organization
    2025-12-11
    (CWE 4.19, 2025-12-11)
    CWE Content Team MITRE
    updated Detection_Factors, Weakness_Ordinalities
    2025-09-09
    (CWE 4.18, 2025-09-09)
    CWE Content Team MITRE
    updated Common_Consequences, Description, Diagram
    2023-10-26
    (CWE 4.13, 2023-10-26)
    CWE Content Team MITRE
    updated Observed_Examples
    2023-06-29
    (CWE 4.12, 2023-06-29)
    CWE Content Team MITRE
    updated Mapping_Notes
    2023-04-27
    (CWE 4.11, 2023-04-27)
    CWE Content Team MITRE
    updated Relationships, Time_of_Introduction
    2023-01-31
    (CWE 4.10, 2023-01-31)
    CWE Content Team MITRE
    updated Description
    2022-10-13
    (CWE 4.9, 2022-10-13)
    CWE Content Team MITRE
    updated Relationships, Taxonomy_Mappings
    2021-03-15
    (CWE 4.4, 2021-03-15)
    CWE Content Team MITRE
    updated Demonstrative_Examples
    2020-12-10
    (CWE 4.3, 2020-12-10)
    CWE Content Team MITRE
    updated Relationships
    2020-08-20
    (CWE 4.2, 2020-08-20)
    CWE Content Team MITRE
    updated Relationships
    2020-02-24
    (CWE 4.0, 2020-02-24)
    CWE Content Team MITRE
    updated Applicable_Platforms, Relationships, Taxonomy_Mappings
    2019-09-19
    (CWE 3.4, 2019-09-19)
    CWE Content Team MITRE
    updated Description, Relationships
    2019-06-20
    (CWE 3.3, 2019-06-20)
    CWE Content Team MITRE
    updated Relationships
    2019-01-03
    (CWE 3.2, 2019-01-03)
    CWE Content Team MITRE
    updated Common_Consequences, References, Relationships, Taxonomy_Mappings
    2017-11-08
    (CWE 3.0, 2017-11-08)
    CWE Content Team MITRE
    updated Likelihood_of_Exploit, Taxonomy_Mappings
    2017-01-19
    (CWE 2.10, 2017-01-19)
    CWE Content Team MITRE
    updated Relationships
    2014-07-30
    (CWE 2.8, 2014-07-31)
    CWE Content Team MITRE
    updated Relationships, Taxonomy_Mappings
    2014-02-18
    (CWE 2.6, 2014-02-19)
    CWE Content Team MITRE
    updated Applicable_Platforms, Demonstrative_Examples
    2013-02-21
    (CWE 2.4, 2013-02-21)
    CWE Content Team MITRE
    updated Relationships
    2012-10-30
    (CWE 2.3, 2012-10-30)
    CWE Content Team MITRE
    updated Potential_Mitigations
    2012-05-11
    (CWE 2.2, 2012-05-15)
    CWE Content Team MITRE
    updated Demonstrative_Examples, Relationships, Taxonomy_Mappings
    2011-09-13
    (CWE 2.1, 2011-09-13)
    CWE Content Team MITRE
    updated Relationships, Taxonomy_Mappings
    2011-06-27
    (CWE 2.0, 2011-06-27)
    CWE Content Team MITRE
    updated Observed_Examples, Related_Attack_Patterns, Relationships
    2011-06-01
    (CWE 1.13, 2011-06-01)
    CWE Content Team MITRE
    updated Common_Consequences, Relationships, Taxonomy_Mappings
    2010-06-21
    (CWE 1.9, 2010-06-21)
    CWE Content Team MITRE
    updated Potential_Mitigations
    2010-04-05
    (CWE 1.8.1, 2010-04-05)
    CWE Content Team MITRE
    updated Potential_Mitigations
    2010-02-16
    (CWE 1.8, 2010-02-16)
    CWE Content Team MITRE
    updated Demonstrative_Examples, Potential_Mitigations, Relationships
    Page Last Updated: April 30, 2026