CWE - CWE-404: Improper Resource Shutdown or Release (4.19.1)
Home > CWE List > CWE-404: Improper Resource Shutdown or Release (4.19.1)  
ID

  • Home
  • CWE-404: Improper Resource Shutdown or Release

    Weakness ID: 404
    Vulnerability Mapping: ALLOWED This CWE ID could be used to map to real-world vulnerabilities in limited situations requiring careful review (with careful review of mapping notes)
    Abstraction: 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.
    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 or incorrectly releases a resource before it is made available for re-use.
    + Extended Description
    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.
    + 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); Varies by Context

    Scope: Availability, Other

    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.

    Read Application Data

    Scope: Confidentiality

    When a resource containing sensitive information is not correctly shutdown, it may expose the sensitive data in a subsequent allocation.
    + 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 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.
    + 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 Pillar Pillar - a weakness that is the most abstract type of weakness and represents a theme for all class/base/variant weaknesses related to it. A Pillar is different from a Category as a Pillar is still technically a type of weakness that describes a mistake, while a Category represents a common characteristic used to group related things. 664 Improper Control of a Resource Through its 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. 299 Improper Check for Certificate Revocation
    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. 459 Incomplete Cleanup
    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. 763 Release of Invalid Pointer or Reference
    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. 772 Missing Release of Resource 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. 1266 Improper Scrubbing of Sensitive Data from Decommissioned Device
    PeerOf 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. 239 Failure to Handle Incomplete Element
    PeerOf 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. 405 Asymmetric Resource Consumption (Amplification)
    CanPrecede 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. 619 Dangling Database Cursor ('Cursor Injection')
    + Relevant to the view "Weaknesses for Simplified Mapping of Published Vulnerabilities" (View-1003)
    Nature Type ID Name
    MemberOf View View - 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). 1003 Weaknesses for Simplified Mapping of Published Vulnerabilities
    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 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. 459 Incomplete Cleanup
    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. 763 Release of Invalid Pointer or Reference
    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. 772 Missing Release of Resource after Effective Lifetime
    + Relevant to the view "CISQ Quality Measures (2020)" (View-1305)
    Nature Type ID Name
    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 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. 772 Missing Release of Resource 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
    + Relevant to the view "CISQ Data Protection Measures" (View-1340)
    Nature Type ID Name
    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. 761 Free of Pointer not at Start of Buffer
    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. 762 Mismatched Memory Management Routines
    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. 763 Release of Invalid Pointer or Reference
    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. 772 Missing Release of Resource 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
    + 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.
    Languages

    Class: Not Language-Specific (Undetermined Prevalence)

    + Likelihood Of Exploit
    Medium
    + 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


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


    + 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
    Does not shut down named pipe connections if malformed data is sent.
    Sockets not properly closed when attacker repeatedly connects and disconnects from server.
    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)
    Improper release or shutdown of resources can be primary to resource exhaustion, performance, and information confidentiality problems to name a few.
    Resultant
    (where the weakness is typically related to the presence of some other weaknesses)
    Improper release or shutdown of resources can be resultant from improper error handling or insufficient resource tracking.
    + Detection Methods
    Method Details

    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

    + 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. 398 7PK - Code Quality
    MemberOf CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. 730 OWASP Top Ten 2004 Category A9 - Denial of Service
    MemberOf CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. 743 CERT C Secure Coding Standard (2008) Chapter 10 - Input Output (FIO)
    MemberOf CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. 752 2009 Top 25 - Risky Resource Management
    MemberOf CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. 857 The CERT Oracle Secure Coding Standard for Java (2011) Chapter 14 - Input Output (FIO)
    MemberOf CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. 876 CERT C++ Secure Coding Section 08 - Memory Management (MEM)
    MemberOf CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. 877 CERT C++ Secure Coding Section 09 - Input Output (FIO)
    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 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. 1147 SEI CERT Oracle Secure Coding Standard for Java - Guidelines 13. Input Output (FIO)
    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 CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. 1306 CISQ Quality Measures - Reliability
    MemberOf CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. 1308 CISQ Quality Measures - Security
    MemberOf CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. 1309 CISQ Quality Measures - Efficiency
    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). 1340 CISQ Data Protection Measures
    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-WITH-REVIEW
    (this CWE ID could be used to map to real-world vulnerabilities in limited situations requiring careful review)
    Reason Abstraction

    Rationale

    This CWE entry is a Class and might have Base-level children that would be more appropriate

    Comments

    Examine children of this entry to see if there is a better fit
    + Notes

    Relationship

    Overlaps memory leaks, asymmetric resource consumption, malformed input errors.
    + Taxonomy Mappings
    Mapped Taxonomy Name Node ID Fit Mapped Node Name
    PLOVER Improper resource shutdown or release
    7 Pernicious Kingdoms Unreleased Resource
    OWASP Top Ten 2004 A9 CWE More Specific Denial of Service
    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
    The CERT Oracle Secure Coding Standard for Java (2011) FIO04-J Release resources when they are no longer needed
    Software Fault Patterns SFP14 Failure to release resource
    + References
    [REF-44] Michael Howard, David LeBlanc and John Viega. "24 Deadly Sins of Software Security". "Sin 8: C++ Catastrophes." Page 143. McGraw-Hill. 2010.
    + Content History
    + Submissions
    Submission Date Submitter Organization
    2006-07-19
    (CWE Draft 3, 2006-07-19)
    PLOVER
    + Modifications
    Modification Date Modifier Organization
    2023-10-26 CWE Content Team MITRE
    updated Observed_Examples
    2023-06-29 CWE Content Team MITRE
    updated Mapping_Notes
    2023-04-27 CWE Content Team MITRE
    updated Detection_Factors, Relationships, Time_of_Introduction
    2023-01-31 CWE Content Team MITRE
    updated Description, Detection_Factors
    2022-10-13 CWE Content Team MITRE
    updated Relationships
    2021-07-20 CWE Content Team MITRE
    updated Related_Attack_Patterns
    2021-03-15 CWE Content Team MITRE
    updated Demonstrative_Examples
    2020-12-10 CWE Content Team MITRE
    updated Relationships
    2020-08-20 CWE Content Team MITRE
    updated Relationships
    2020-06-25 CWE Content Team MITRE
    updated Relationships
    2020-02-24 CWE Content Team MITRE
    updated Relationships
    2019-06-20 CWE Content Team MITRE
    updated Related_Attack_Patterns, Relationships
    2019-01-03 CWE Content Team MITRE
    updated Relationships, Taxonomy_Mappings, Type
    2017-11-08 CWE Content Team MITRE
    updated Applicable_Platforms, Functional_Areas, Likelihood_of_Exploit, Relationships, Taxonomy_Mappings
    2017-05-03 CWE Content Team MITRE
    updated Related_Attack_Patterns
    2017-01-19 CWE Content Team MITRE
    updated Relationships
    2015-12-07 CWE Content Team MITRE
    updated Relationships
    2014-07-30 CWE Content Team MITRE
    updated Relationships, Taxonomy_Mappings
    2014-06-23 CWE Content Team MITRE
    updated Related_Attack_Patterns
    2014-02-18 CWE Content Team MITRE
    updated Demonstrative_Examples
    2012-05-11 CWE Content Team MITRE
    updated Demonstrative_Examples, References, Relationships, Taxonomy_Mappings
    2011-09-13 CWE Content Team MITRE
    updated Relationships, Taxonomy_Mappings
    2011-06-27 CWE Content Team MITRE
    updated Common_Consequences
    2011-06-01 CWE Content Team MITRE
    updated Common_Consequences, Relationships, Taxonomy_Mappings
    2011-03-29 CWE Content Team MITRE
    updated Weakness_Ordinalities
    2010-12-13 CWE Content Team MITRE
    updated Demonstrative_Examples
    2010-06-21 CWE Content Team MITRE
    updated Detection_Factors, Potential_Mitigations
    2010-02-16 CWE Content Team MITRE
    updated Potential_Mitigations, Relationships
    2009-10-29 CWE Content Team MITRE
    updated Other_Notes
    2009-07-27 CWE Content Team MITRE
    updated Demonstrative_Examples, Related_Attack_Patterns
    2009-05-27 CWE Content Team MITRE
    updated Description, Relationships
    2009-03-10 CWE Content Team MITRE
    updated Potential_Mitigations
    2009-01-12 CWE Content Team MITRE
    updated Common_Consequences, Likelihood_of_Exploit, Other_Notes, Potential_Mitigations, Relationship_Notes, Relationships, Weakness_Ordinalities
    2008-11-24 CWE Content Team MITRE
    updated Relationships, Taxonomy_Mappings
    2008-10-14 CWE Content Team MITRE
    updated Relationships
    2008-09-08 CWE Content Team MITRE
    updated Description, Relationships, Other_Notes, Taxonomy_Mappings
    2008-08-15 Veracode
    Suggested OWASP Top Ten 2004 mapping
    2008-07-01 Eric Dalci Cigital
    updated Time_of_Introduction
    Page Last Updated: January 21, 2026