Skip to content

Use After Free

Description

The use of previously-freed memory can have adverse consequences, ranging from data corruption to the execution of arbitrary code, depending on the instantiation and timing of the flaw.

Examples

Insecure Code

c
void func() { int* ptr = malloc(10); free(ptr); *ptr = 5; }

Secure Code

c
void func() { int* ptr = malloc(10); free(ptr); ptr = NULL; }

Remediation

Ensure that memory is not accessed after it has been freed. Assign a new value to the pointer after freeing it to prevent accidental use.

Rule Details

FieldValue
IDCODE-0680
CategoryGeneric
SeverityCRITICAL
CWECWE-416
ConfidenceMEDIUM
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityMODERATE
Tagsmemory, use-after-free
OWASPN/A

References