This vulnerability occurs when a program tries to free a memory resource back to the system but uses an incorrect deallocation method or calls the correct method improperly.
This issue typically arises from mismatched memory management functions. For example, memory allocated with one function (like `malloc`) is incorrectly freed using a non-compatible function from a different API (like `delete`), leading to heap corruption and instability. This mismatch, often called CWE-762, breaks the underlying memory manager's expectations. Even when using the correct function pair, developers can misuse them. A common mistake is calling the deallocation function with an invalid pointer—such as one that was already freed, points to stack memory, or was never allocated. This scenario, related to CWE-761, causes crashes or undefined behavior because the system cannot process the flawed release request.
Impact: Modify MemoryDoS: Crash, Exit, or RestartExecute Unauthorized Code or Commands
This weakness may result in the corruption of memory, and perhaps instructions, possibly leading to a crash. If the corrupted memory can be effectively controlled, it may be possible to execute arbitrary code.
Strategy: Libraries or Frameworks
cc++
/* do some work with ptr here /
c++c++
/* do some work with ptr here /
c++c
/* matched char, free string and return success / free(str); return SUCCESS;}
cc
/* matched char, free string and return success / free(str); return SUCCESS;}
c//hardcode input length for simplicity* char* input = (char*) malloc(40*sizeof(char)); char tok; char sep = " \t";
c
c//hardcode input length for simplicity* char* input = (char*) malloc(40*sizeof(char)); char *tok, command; char sep = " \t";
c
c