CWEweakness

CWE-590 Free of Memory not on the Heap

Official page ↗
Abstraction
Variant
Structure
Simple
Status
Incomplete
Languages
C, Memory-Unsafe
CWE version
5.0

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

Common consequences

• 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] 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. • 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.) • 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].

Observed examples

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

Related

Observed example · CVE (1)

  • CVE-2023-22291 An invalid free vulnerability exists in the Frame stream parser functionality of Ichitaro 2022 1.0.1.57600. vulnerability

Can precede · CWE (1)

  • CWE-123 Write-what-where Condition weakness

Child of · CWE (1)

  • CWE-762 Mismatched Memory Management Routines weakness

Referenced by CVE · weakness (26)

  • CVE-2026-68908 libIEC61850 is an open-source implementation of IEC 61850 client and server protocols including MMS, GOOSE, Sampled Values, and R-Session. vulnerability
  • CVE-2026-94370 A defect in the Qt for MCUs core string handling causes heap memory corruption. vulnerability
  • CVE-2026-106578 ImageMagick is free and open-source software used for editing and manipulating digital images. vulnerability
  • CVE-2026-76465 A vulnerability in the MPLS Operation, Administration, and Maintenance (OAM) feature of Cisco NX-OS Software for Cisco Nexus 3000 Series… vulnerability
  • CVE-2026-95311 Free of non-heap memory in Fonts in Google Chrome prior to 154.0.8037.57 allowed a remote attacker leveraging social engineering to… vulnerability
  • CVE-2026-89161 In PCRE2 before 10.48, pcre2_jit_match mishandles a previously copied subject being passed in as a context. vulnerability
  • CVE-2026-18582 A security flaw has been discovered in mz-automation libiec61850 up to 1.6.1. vulnerability
  • CVE-2025-7006 Use of stack memory after free vulnerability in Avast Antivirus when scanning a malformed Windows PE file may allow Denial-of-Service of… vulnerability
  • CVE-2026-47328 Ubuntu Linux 6.8, 6.17 and 7.0 contain AppArmor SAUCE patches which incorrectly attempt to free a pointer which was not previously… vulnerability
  • CVE-2026-20810 Free of memory not on the heap in Windows Ancillary Function Driver for WinSock allows an authorized attacker to elevate privileges locally. vulnerability
  • CVE-2025-54899 Free of memory not on the heap in Microsoft Office Excel allows an unauthorized attacker to execute code locally. vulnerability
  • CVE-2025-42994 SAP MDM Server ReadString function allows an attacker to send specially crafted packets which could trigger a memory read access violation… vulnerability
  • CVE-2025-42995 SAP MDM Server Read function allows an attacker to send specially crafted packets which could trigger a memory read access violation in the… vulnerability
  • CVE-2025-42996 SAP MDM Server allows an attacker to gain control of existing client sessions and execute certain functions without having to… vulnerability
  • CVE-2025-5899 A vulnerability classified as critical was found in GNU PSPP 82fb509fb2fedd33e7ac0c46ca99e108bb3bdffb. vulnerability
  • CVE-2025-32911 A use-after-free type vulnerability was found in libsoup, in the soup_message_headers_get_content_disposition() function. vulnerability
  • CVE-2023-42459 Fast DDS is a C++ implementation of the DDS (Data Distribution Service) standard of the OMG (Object Management Group). vulnerability
  • CVE-2023-31973 yasm v1.3.0 was discovered to contain a use after free via the function expand_mmac_params at /nasm/nasm-pp.c. vulnerability
  • CVE-2023-22291 An invalid free vulnerability exists in the Frame stream parser functionality of Ichitaro 2022 1.0.1.57600. vulnerability
  • CVE-2023-25565 GSS-NTLMSSP is a mechglue plugin for the GSSAPI library that implements NTLM authentication. vulnerability
  • CVE-2022-31627 In PHP versions 8.1.x below 8.1.8, when fileinfo functions, such as finfo_buffer, due to incorrect patch applied to the third party code… vulnerability
  • CVE-2022-31625 In PHP versions 7.4.x below 7.4.30, 8.0.x below 8.0.20, and 8.1.x below 8.1.7, when using Postgres database extension, supplying invalid… vulnerability
  • CVE-2021-3939 Ubuntu-specific modifications to accountsservice (in patch file debian/patches/0010-set-language.patch) caused the fallback_locale… vulnerability
  • 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… vulnerability
  • CVE-2021-39218 Wasmtime is an open source runtime for WebAssembly & WASI. vulnerability
  • CVE-2020-6016 Valve's Game Networking Sockets prior to version v1.2.0 improperly handles unreliable segments with negative offsets in function… vulnerability