Skip to content

Incorrect use of free() on stack variable

Description

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

Examples

Insecure Code

c
int arr[10]; free(arr);

Secure Code

c
int* arr = malloc(10 * sizeof(int)); free(arr);

Remediation

Use stack variables or dynamically allocated memory with correct allocation and deallocation functions.

Rule Details

FieldValue
IDCODE-0286
CategoryGeneric
SeverityCRITICAL
CWECWE-590
ConfidenceMEDIUM
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityEASY
Tagsmemory, allocation
OWASPN/A

References