The product uses, accesses, or otherwise operates on a resource after that resource has been expired, released, or revoked.
View on MITREIf a released resource is subsequently reused or reallocated, then an attempt to use the original resource might allow access to sensitive data that is associated with a different user or entity.
When a resource is released it might not be in an expected state, later attempts to access the resource may lead to resultant errors that may lead to a crash.
No mitigation information available for this CWE.
No detection method information available for this CWE.
The following code shows a simple example of a use after free error:
When an error occurs, the pointer is immediately freed. However, this pointer is later incorrectly used in the logError function.
The following code shows a simple example of a double free error:
Double free vulnerabilities have two common (and sometimes overlapping) causes:
In the following C/C++ example the method processMessage is used to process a message received in the input array of char arrays. The input message array contains two char arrays: the first is the length of the message and the second is the body of the message. The length of the message is retrieved and used to allocate enough memory for a local char array, messageBody, to be created for the message body. The messageBody is processed in the method processMessageBody that will return an error if an error occurs while processing. If an error occurs then the return result variable is set to indicate an error and the messageBody char array memory is released using the method free and an error message is sent to the logError method.
However, the call to the method logError includes the messageBody after the memory for messageBody has been released using the free method. This can cause unexpected results and may lead to system crashes. A variable should never be used after its memory resources have been released.
In the following C/C++ example the method processMessage is used to process a message received in the input array of char arrays. The input message array contains two char arrays: the first is the length of the message and the second is the body of the message. The length of the message is retrieved and used to allocate enough memory for a local char array, messageBody, to be created for the message body. The messageBody is processed in the method processMessageBody that will return an error if an error occurs while processing. If an error occurs then the return result variable is set to indicate an error and the messageBody char array memory is released using the method free and an error message is sent to the logError method.
However, the call to the method logError includes the messageBody after the memory for messageBody has been released using the free method. This can cause unexpected results and may lead to system crashes. A variable should never be used after its memory resources have been released.
Chain: race condition (CWE-362) might allow resource to be released before operating on it, leading to NULL dereference (CWE-476)
View DetailsCWE-672: Operation on a Resource after Expiration or Release is a Common Weakness Enumeration (CWE) entry maintained by MITRE. The product uses, accesses, or otherwise operates on a resource after that resource has been expired, released, or revoked.
If exploited, CWE-672 (Operation on a Resource after Expiration or Release) it can compromise Integrity, Confidentiality, Other and Availability, leading to outcomes such as Modify Application Data, Read Application Data, Other and DoS: Crash, Exit, or Restart.
CWE-672 commonly affects Not Language-Specific. Note that weaknesses are often language-agnostic patterns, so secure coding practices apply broadly.
MITRE documents real CVEs mapped to CWE-672, including CVE-2009-3547. You can look up the full details of each CVE, including CVSS scores and remediation guidance, on our CVE Lookup tool.
A CWE (Common Weakness Enumeration) like CWE-672 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.