Mismatched memory allocation and deallocation functions
ID |
c.memory_management.mismatched_memory_management |
Severity |
low |
Remediation Complexity |
hard |
Remediation Risk |
high |
Remediation Effort |
medium |
Resource |
Memory Management |
Language |
C / C++ |
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. Matching is syntactic, so an allocation and its release cannot be paired across a function boundary: review the findings and tune the allocator and deallocator lists to the ones your codebase actually uses.
Rationale
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. Matching is syntactic, so an allocation and its release cannot be paired across a function boundary: review the findings and tune the allocator and deallocator lists to the ones your codebase actually uses.
The following code illustrates a vulnerable pattern detected by this rule:
void bad1()
{
int localArray[2] = {11, 22};
int *p = localArray;
// VULNERABLE: Mismatched memory allocation and deallocation functions
free(p);
}
Remediation
Follow secure coding practices and review the references below for detailed remediation guidance.