---
title: "CWE-590: Free of Memory not on the Heap"
url: https://radicalnotion.ai/cwe/cwe-590
type: cwe
description: "The product calls free() on a pointer to memory that was not allocated using associated heap allocation functions such as malloc(), calloc(), or realloc()."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-590: Free of Memory not on the Heap

- **Abstraction:** Variant
- **Structure:** Simple
- **Status:** Incomplete
- **CVEs with this as primary weakness:** 25
- **Of those, in CISA KEV:** 0
- **New in 2026:** 9
- **CWE catalog version:** 4.21

## Description

The product calls free() on a pointer to memory that was not allocated using associated heap allocation functions such as malloc(), calloc(), or realloc().

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | - |

## Applicable platforms

**Languages:** Memory-Unsafe (Undetermined), C (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Integrity, Confidentiality, Availability | Execute Unauthorized Code or Commands, Modify Memory | 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. There is the potential for arbitrary code execution with privileges of the vulnerable program via a "write, what where" primitive. If pointers to memory that hold user information are freed, a malicious user may be able to write 4 bytes anywhere in memory. |

## Potential mitigations

### Implementation

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.

### Implementation

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.

### Architecture and Design (Libraries or Frameworks)

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.

### Architecture and Design

Use a language that provides abstractions for memory allocation and deallocation.

## Detection methods

### 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

### 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\] or valgrind \[REF-480\].

Effectiveness: 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.

## Demonstrative examples

### Example 1

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.

Bad code:

```c
void foo(){
    record_t bar[MAX_SIZE];

    /* do something interesting with bar */

    ...
    free(bar);
}
```

Bad code:

```c
record_t bar[MAX_SIZE]; //Global var
void foo(){

    /* do something interesting with bar */
    ...
    free(bar);
}
```

Good code:

```c
void foo(){
    record_t *bar = (record_t*)malloc(MAX_SIZE*sizeof(record_t));

    /* do something interesting with bar */

    ...
    free(bar);
}
```

Good code:

```c
record_t *bar; //Global var
void foo(){
    bar = (record_t*)malloc(MAX_SIZE*sizeof(record_t));

    /* do something interesting with bar */

    ...
    free(bar);
}
```

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2023-22291 | parser for a word processor attempts to free a stack pointer when intending to expand memory to hold a larger buffer |

## Real CVEs with this weakness (sample of 12 of 25)

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2026-76465 | Cisco Nexus 3000 and 9000 Series Switches MPLS OAM Remote Code Execution Vulnerability | critical | 9.8 | - | No | 2026-10-07 |
| CVE-2022-31627 | Heap buffer overflow in finfo\_buffer | critical | 9.8 | - | No | 2022-07-28 |
| CVE-2021-42377 | An attacker-controlled pointer free in Busybox's hush applet leads to denial of service and possible code execution when processing a crafted shell command, due to the shell mishandling the &&& string. This may be used for remote code execution under rare conditions of filtered command input. | critical | 9.8 | - | No | 2021-11-15 |
| CVE-2020-6016 | - | critical | 9.8 | - | No | 2020-11-18 |
| CVE-2026-95311 | Free of non-heap memory in Fonts | critical | 9.6 | - | No | 2026-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 | 9.0 | - | No | 2025-04-15 |
| CVE-2024-6197 | freeing stack buffer in utf8asn1str | high | 8.8 | - | No | 2024-07-24 |
| CVE-2022-31625 | Freeing unallocated memory in php\_pgsql\_free\_params() | high | 8.1 | - | No | 2022-06-16 |
| CVE-2026-89161 | pcre2: PCRE2: Memory corruption vulnerability in pcre2\_jit\_match | high | 7.8 | - | No | 2026-09-11 |
| CVE-2026-20810 | Windows Ancillary Function Driver for WinSock Elevation of Privilege Vulnerability | high | 7.8 | - | No | 2026-01-13 |
| CVE-2025-54899 | Microsoft Excel Remote Code Execution Vulnerability | high | 7.8 | - | No | 2025-09-09 |
| CVE-2023-22291 | Free of Memory not on the Heap in Hanako and other products | high | 7.8 | - | No | 2023-04-05 |

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-762](https://radicalnotion.ai/cwe/cwe-762) | Mismatched Memory Management Routines |
| Can precede | [CWE-123](https://radicalnotion.ai/cwe/cwe-123) | Write-what-where Condition |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| CERT C Secure Coding | Only free memory allocated dynamically | MEM34-C | Exact |
| CERT C Secure Coding | Properly pair allocation and deallocation functions | WIN30-C | Imprecise |
| Software Fault Patterns | Faulty Memory Release | SFP12 | - |

## Frequently asked questions

### 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?

25 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?

25 recorded CVEs are caused by CWE-590; none are currently in CISA's KEV catalog of actively exploited flaws.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/590.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-590). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
