Skip to content

Mismatched Memory Management

Description

The software attempts to return a memory resource to the system, but it calls a release function that is not compatible with the function that was originally used to allocate that resource.

Examples

Insecure Code

cpp
void* ptr = malloc(10); delete ptr;

Secure Code

cpp
void* ptr = malloc(10); free(ptr);

Remediation

Use the correct release function corresponding to the allocation function. For example, use free() with malloc(), delete[] with new[], and delete with new.

Rule Details

FieldValue
IDCODE-0287
CategoryGeneric
SeverityMEDIUM
CWECWE-762
ConfidenceLOW
ImpactMEDIUM
LikelihoodMEDIUM
ExploitabilityMODERATE
Tagsmemory management, cpp
OWASPN/A

References