CWE-590: Free of Memory not on the Heap
The product calls free() on a pointer to memory that was not allocated using associated heap allocation functions such as malloc(), calloc(), or realloc().
Last updated
Overview
When free() is called on an invalid pointer, the program's memory management data structures may become corrupted. This corruption can cause the program to crash or, in some circumstances, an attacker may be able to cause free() to operate on controllable memory locations to modify critical program variables or execute code.
Real-world CVEs
22 recorded CVEs are caused by CWE-590 (Free of Memory not on the Heap). The highest-severity and most recent are shown first. 9 new CWE-590 CVEs have been recorded so far in 2026 (6 in 2025).
- CVE-2026-76465
Cisco Nexus 3000 and 9000 Series Switches MPLS OAM Remote Code Execution Vulnerability
Critical · CVSS 9.8 · EPSS 40th2026-10-07 - CVE-2022-31627
Heap buffer overflow in finfo_buffer
Critical · CVSS 9.8 · EPSS 82th2022-07-28 - CVE-2021-42377Critical · CVSS 9.8 · EPSS 90th2021-11-15
- CVE-2020-6016Critical · CVSS 9.8 · EPSS 93th2020-11-18
- CVE-2026-95311Critical · CVSS 9.6 · EPSS 28th2026-09-29
- CVE-2025-32911
Libsoup: double free on soup_message_headers_get_content_disposition() through "soup-message-headers.c" via "params" ghashtable value
Critical · CVSS 9.0 · EPSS 62th2025-04-15 - CVE-2022-31625
Freeing unallocated memory in php_pgsql_free_params()
High · CVSS 8.1 · EPSS 90th2022-06-16 - CVE-2026-89161High · CVSS 7.8 · EPSS 2th2026-09-11
- CVE-2026-20810
Windows Ancillary Function Driver for WinSock Elevation of Privilege Vulnerability
High · CVSS 7.8 · EPSS 42th2026-01-13 - CVE-2025-54899
Microsoft Excel Remote Code Execution Vulnerability
High · CVSS 7.8 · EPSS 48th2025-09-09 - CVE-2023-22291High · CVSS 7.8 · EPSS 40th2023-04-05
- CVE-2021-3939
Free of static data in accountsservice
High · CVSS 7.8 · EPSS 31th2021-11-17
Showing 12 of 22 recorded CWE-590 CVEs. Get an alert for each new one, with AI-written analysis and fixes.
Monitor these CVEsCommon consequences
What can happen when CWE-590 is exploited.
Execute Unauthorized Code or Commands, Modify Memory
Affects: Integrity, Confidentiality, Availability
There is the potential for arbitrary code execution with privileges of the vulnerable program via a "write, what where" primitive. If pointers to memory which hold user information are freed, a malicious user will be able to write 4 bytes anywhere in memory.
How it happens
When it is introduced
Typically introduced during these phases of the software lifecycle.
Applies to
Languages
How to prevent it
Practical mitigations for CWE-590, grouped by where in the lifecycle they apply.
Only free pointers that you have called malloc on previously. This is the recommended solution. Keep track of which pointers point at the beginning of valid chunks and free them only once.
Before freeing a pointer, the programmer should make sure that the pointer was previously allocated on the heap and that the memory belongs to the programmer. Freeing an unallocated pointer will cause undefined behavior in the program.
Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid.
For example, glibc in Linux provides protection against free of invalid pointers.
Use a language that provides abstractions for memory allocation and deallocation.
How to detect it
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.
Effectiveness: 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.)
Effectiveness: High
Code examples
MITRE examples of the weakness in code.
In this example, an array of record_t structs, bar, is allocated automatically on the stack as a local variable and the programmer attempts to call free() on the array. The consequences will vary based on the implementation of free(), but it will not succeed in deallocating the memory.
Vulnerable example
void foo(){
record_t bar[MAX_SIZE];
/* do something interesting with bar */Vulnerable example
record_t bar[MAX_SIZE]; //Global var
/* do something interesting with bar */Safe example
void foo(){
record_t *bar = (record_t*)malloc(MAX_SIZE*sizeof(record_t));
/* do something interesting with bar */Safe example
record_t *bar; //Global var
bar = (record_t*)malloc(MAX_SIZE*sizeof(record_t));
/* do something interesting with bar */Illustrative examples
Real CVEs that MITRE cites as examples of this weakness.
- CVE-2023-22291 — parser for a word processor attempts to free a stack pointer when intending to expand memory to hold a larger buffer
Terminology & mappings
Mapped taxonomies
- CERT C Secure Coding: Only free memory allocated dynamically (MEM34-C) — Exact fit
- CERT C Secure Coding: Properly pair allocation and deallocation functions (WIN30-C) — Imprecise fit
- Software Fault Patterns: Faulty Memory Release (SFP12)
Frequently asked questions
Common questions about CWE-590.
- What is CWE-590?
- The product calls free() on a pointer to memory that was not allocated using associated heap allocation functions such as malloc(), calloc(), or realloc().
- What CVEs are caused by CWE-590?
- 22 recorded CVEs are attributed to CWE-590, including CVE-2026-76465, CVE-2022-31627 and CVE-2021-42377.
- How do you prevent CWE-590?
- Only free pointers that you have called malloc on previously. This is the recommended solution. Keep track of which pointers point at the beginning of valid chunks and free them only once.
- How is CWE-590 detected?
- 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.
- What are the consequences of CWE-590?
- Exploiting CWE-590 can lead to: Execute Unauthorized Code or Commands, Modify Memory.
- Is CWE-590 actively exploited?
- 22 recorded CVEs are caused by CWE-590; none are currently in CISA's KEV catalog of actively exploited flaws.
Sources
- [1]Valgrind
- [2]AddressSanitizer
References
- MITRE CWE definition (CWE-590) (opens in a new tab)
- CWE-590 vulnerabilities on NVD (opens in a new tab)
- Learn: What is a CWE?
Weakness data is sourced from the MITRE CWE catalog (v4.20). CVE associations are aggregated and kept current by RadicalNotion.AI.
Track CWE-590 CVEs
Get an alert when a new CWE-590 CVE affects your products, with AI-written analysis and remediation steps.