Skip to content

Double Free Vulnerability

Description

The software calls free() twice on the same memory address, potentially leading to memory corruption. This corruption can cause the program to crash or cause two later calls to malloc() to return the same pointer.

Examples

Insecure Code

c
void example() {
  int* ptr = malloc(sizeof(int));
  free(ptr);
  free(ptr);
}

Secure Code

c
void example() {
  int* ptr = malloc(sizeof(int));
  free(ptr);
  ptr = NULL;
}

Remediation

Ensure that free() is only called once on each allocated memory address. Consider using smart pointers or other memory management techniques to prevent double-free vulnerabilities.

Rule Details

FieldValue
IDCODE-0224
CategoryGeneric
SeverityCRITICAL
CWECWE-415
ConfidenceMEDIUM
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityEASY
Tagsmemory-corruption, double-free
OWASPN/A

References