The product reuses or references memory after it has been freed. At some point afterward, the memory may be allocated again and saved in another pointer, while the original pointer references a location somewhere within the new allocation. Any operations using the original pointer are no longer valid because the memory "belongs" to the code that operates on the new pointer.

Resultant
If the product accesses a previously-freed pointer, then it means that a separate weakness or error already occurred previously, such as a race condition, an unexpected or poorly handled error condition, confusion over which part of the program is responsible for freeing the memory, performing the free too soon, etc.

Dangling pointer
a pointer that no longer points to valid memory, often after it has been freed

UAF
commonly used acronym for Use After Free

Use-After-Free

Implementation

High

Integrity
Modify Memory
The use of previously freed memory may corrupt valid data, if the memory area in question has been allocated and used properly elsewhere.

Availability
DoS: Crash, Exit, or Restart
If chunk consolidation occurs after the use of previously freed data, the process may crash when invalid data is used as chunk information.

Integrity
Confidentiality
Availability
Execute Unauthorized Code or Commands
If malicious data is entered before chunk consolidation can take place, it may be possible to take advantage of a write-what-where primitive to execute arbitrary code. If the newly allocated data happens to hold a class, in C++ for example, various function pointers may be scattered within the heap data. If one of these function pointers is overwritten with an address to valid shellcode, execution of arbitrary code can be achieved.

Fuzzing
Fuzz testing (fuzzing) is a powerful technique for generating large numbers of diverse inputs - either randomly or algorithmically - and dynamically invoking the code with those inputs. Even with random inputs, it is often capable of generating unexpected results such as crashes, memory corruption, or resource consumption. Fuzzing effectively produces repeatable test cases that clearly indicate bugs, which helps developers to diagnose the issues.
High

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.)
High

Automated Dynamic Analysis
Use tools that are integrated during
compilation to insert runtime error-checking mechanisms
related to memory safety errors, such as AddressSanitizer
(ASan) for C/C++ [REF-1518].
Moderate
Crafted inputs are necessary to
reach the code containing the error, such as generated
by fuzzers. Also, these tools may reduce performance,
and they only report the error condition - not the
original mistake that led to the
error.

Architecture and Design
Language Selection
Choose a language that provides automatic memory management.

Implementation
Attack Surface Reduction
When freeing pointers, be sure to set them to NULL once they are freed. However, the utilization of multiple or complex data structures may lower the usefulness of this strategy.
Defense in Depth
If a bug causes an attempted access of this pointer, then a NULL dereference could still lead to a crash or other unexpected behavior, but it will reduce or eliminate the risk of code execution.

The following example demonstrates the weakness.

#include <stdio.h>#include <unistd.h>#define BUFSIZER1 512#define BUFSIZER2 ((BUFSIZER1/2) - 8)int main(int argc, char **argv) {char *buf1R1;char *buf2R1;char *buf2R2;char *buf3R2;buf1R1 = (char *) malloc(BUFSIZER1);buf2R1 = (char *) malloc(BUFSIZER1);free(buf2R1);buf2R2 = (char *) malloc(BUFSIZER2);buf3R2 = (char *) malloc(BUFSIZER2);strncpy(buf2R1, argv[1], BUFSIZER1-1);free(buf1R1);free(buf2R2);free(buf3R2);}

The following code illustrates a use after free error:

char* ptr = (char*)malloc (SIZE);if (err) {abrt = 1;free(ptr);}...if (abrt) {logError("operation aborted before commit", ptr);}

When an error occurs, the pointer is immediately freed. However, this pointer is later incorrectly used in the logError function.

CVE-2022-20141
Chain: an operating system kernel has insufficent resource locking (CWE-413) leading to a use after free (CWE-416).
https://www.cve.org/CVERecord?id=CVE-2022-20141

CVE-2022-2621
Chain: two threads in a web browser use the same resource (CWE-366), but one of those threads can destroy the resource before the other has completed (CWE-416).
https://www.cve.org/CVERecord?id=CVE-2022-2621

CVE-2021-0920
Chain: mobile platform race condition (CWE-362) leading to use-after-free (CWE-416), as exploited in the wild per CISA KEV.
https://www.cve.org/CVERecord?id=CVE-2021-0920

CVE-2020-6819
Chain: race condition (CWE-362) leads to use-after-free (CWE-416), as exploited in the wild per CISA KEV.
https://www.cve.org/CVERecord?id=CVE-2020-6819

CVE-2010-4168
Use-after-free triggered by closing a connection while data is still being transmitted.
https://www.cve.org/CVERecord?id=CVE-2010-4168

CVE-2010-2941
Improper allocation for invalid data leads to use-after-free.
https://www.cve.org/CVERecord?id=CVE-2010-2941

CVE-2010-2547
certificate with a large number of Subject Alternate Names not properly handled in realloc, leading to use-after-free
https://www.cve.org/CVERecord?id=CVE-2010-2547

CVE-2010-1772
Timers are not disabled when a related object is deleted
https://www.cve.org/CVERecord?id=CVE-2010-1772

CVE-2010-1437
Access to a "dead" object that is being cleaned up
https://www.cve.org/CVERecord?id=CVE-2010-1437

CVE-2010-1208
object is deleted even with a non-zero reference count, and later accessed
https://www.cve.org/CVERecord?id=CVE-2010-1208

CVE-2010-0629
use-after-free involving request containing an invalid version number
https://www.cve.org/CVERecord?id=CVE-2010-0629

CVE-2010-0378
unload of an object that is currently being accessed by other functionality
https://www.cve.org/CVERecord?id=CVE-2010-0378

CVE-2010-0302
incorrectly tracking a reference count leads to use-after-free
https://www.cve.org/CVERecord?id=CVE-2010-0302

CVE-2010-0249
use-after-free related to use of uninitialized memory
https://www.cve.org/CVERecord?id=CVE-2010-0249

CVE-2010-0050
HTML document with incorrectly-nested tags
https://www.cve.org/CVERecord?id=CVE-2010-0050

CVE-2009-3658
Use after free in ActiveX object by providing a malformed argument to a method
https://www.cve.org/CVERecord?id=CVE-2009-3658

CVE-2009-3616
use-after-free by disconnecting during data transfer, or a message containing incorrect data types
https://www.cve.org/CVERecord?id=CVE-2009-3616

CVE-2009-3553
disconnect during a large data transfer causes incorrect reference count, leading to use-after-free
https://www.cve.org/CVERecord?id=CVE-2009-3553

CVE-2009-2416
use-after-free found by fuzzing
https://www.cve.org/CVERecord?id=CVE-2009-2416

CVE-2009-1837
Chain: race condition (CWE-362) from improper handling of a page transition in web client while an applet is loading (CWE-368) leads to use after free (CWE-416)
https://www.cve.org/CVERecord?id=CVE-2009-1837

CVE-2009-0749
realloc generates new buffer and pointer, but previous pointer is still retained, leading to use after free
https://www.cve.org/CVERecord?id=CVE-2009-0749

CVE-2010-3328
Use-after-free in web browser, probably resultant from not initializing memory.
https://www.cve.org/CVERecord?id=CVE-2010-3328

CVE-2008-5038
use-after-free when one thread accessed memory that was freed by another thread
https://www.cve.org/CVERecord?id=CVE-2008-5038

CVE-2008-0077
assignment of malformed values to certain properties triggers use after free
https://www.cve.org/CVERecord?id=CVE-2008-0077

CVE-2006-4434
mail server does not properly handle a long header.
https://www.cve.org/CVERecord?id=CVE-2006-4434

CVE-2010-2753
chain: integer overflow leads to use-after-free
https://www.cve.org/CVERecord?id=CVE-2010-2753

CVE-2006-4997
freed pointer dereference
https://www.cve.org/CVERecord?id=CVE-2006-4997

CVE-2003-0813
Chain: A multi-threaded race condition (CWE-367) allows attackers to cause two threads to process the same RPC request, which causes a use-after-free (CWE-416) in one thread
https://www.cve.org/CVERecord?id=CVE-2003-0813

Memory Management

Memory

Part 4-1
Req SI-1

Use After Free

Using freed memory

MEM00-C
Allocate and free memory in the same module, at the same level of abstraction

MEM01-C
Store a new value in pointers immediately after free()

MEM30-C
Do not access freed memory
Exact

SFP15
Faulty Resource Use

Allowed
This CWE entry is at the Variant level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities.
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.

7 Pernicious Kingdoms
2006-07-19
Draft 3
2006-07-19

Eric Dalci
Cigital
2008-07-01
updated Potential_Mitigations, Time_of_Introduction

KDM Analytics
2008-08-01
added/updated white box definitions

CWE Content Team
MITRE
2008-09-08
updated Applicable_Platforms, Common_Consequences, Relationships, Observed_Example, Other_Notes, Taxonomy_Mappings

CWE Content Team
MITRE
2008-11-24
updated Relationships, Taxonomy_Mappings

CWE Content Team
MITRE
2009-03-10
updated Demonstrative_Examples

CWE Content Team
MITRE
2009-05-27
updated Demonstrative_Examples

CWE Content Team
MITRE
2009-10-29
updated Common_Consequences

CWE Content Team
MITRE
2010-02-16
updated Relationships

CWE Content Team
MITRE
2010-06-21
updated Potential_Mitigations

CWE Content Team
MITRE
2010-09-27
updated Observed_Examples, Relationships

CWE Content Team
MITRE
2010-12-13
updated Alternate_Terms, Common_Consequences, Description, Observed_Examples, Other_Notes, Potential_Mitigations, Relationships

CWE Content Team
MITRE
2011-03-29
updated Description

CWE Content Team
MITRE
2011-06-01
updated Common_Consequences

CWE Content Team
MITRE
2011-06-27
updated Demonstrative_Examples

CWE Content Team
MITRE
2011-09-13
updated Relationships, Taxonomy_Mappings

CWE Content Team
MITRE
2012-05-11
updated References, Relationships

CWE Content Team
MITRE
2014-07-30
updated Relationships, Taxonomy_Mappings

CWE Content Team
MITRE
2015-12-07
updated Relationships

CWE Content Team
MITRE
2017-11-08
updated Demonstrative_Examples, Relationships, Taxonomy_Mappings, White_Box_Definitions

CWE Content Team
MITRE
2019-01-03
updated Relationships

CWE Content Team
MITRE
2019-06-20
updated Relationships, Type

CWE Content Team
MITRE
2019-09-19
updated Relationships

CWE Content Team
MITRE
2020-02-24
updated References, Relationships, Taxonomy_Mappings

CWE Content Team
MITRE
2020-06-25
updated Relationships

CWE Content Team
MITRE
2020-08-20
updated Relationships

CWE Content Team
MITRE
2020-12-10
updated Relationships

CWE Content Team
MITRE
2021-07-20
updated Relationships

CWE Content Team
MITRE
2022-06-28
updated Observed_Examples, Relationships

CWE Content Team
MITRE
2022-10-13
updated Description, Relationships, Taxonomy_Mappings

CWE Content Team
MITRE
2023-04-27
updated Detection_Factors, Relationships, Time_of_Introduction

CWE Content Team
MITRE
2023-06-29
updated Mapping_Notes, Relationships

CWE Content Team
MITRE
2023-10-26
updated Observed_Examples

CWE Content Team
MITRE
2024-02-29
4.14
2024-02-29
updated Taxonomy_Mappings

CWE Content Team
MITRE
2024-07-16
4.15
2024-07-16
updated Alternate_Terms, Common_Consequences, Description, Diagram, Potential_Mitigations, Relationships, Weakness_Ordinalities

CWE Content Team
MITRE
2024-11-19
4.16
2024-11-19
updated Relationships

CWE Content Team
MITRE
2025-04-03
4.17
2025-04-03
updated Observed_Examples

CWE Content Team
MITRE
2025-09-09
4.18
2025-09-09
updated Functional_Areas

CWE Content Team
MITRE
2025-12-11
4.19
2025-12-11
updated Applicable_Platforms, Detection_Factors, References, Relationships

Anonymous External Contributor
2022-06-28
Suggested rephrase for extended description

participants in the CWE ICS/OT SIG 62443 Mapping Fall Workshop
2023-11-14
4.14
2024-02-29
Contributed or reviewed taxonomy mappings for ISA/IEC 62443

Abhi Balakrishnan
2024-02-29
4.15
2024-07-16
Provided diagram to improve CWE usability