Mismatched memory allocation and deallocation functions
ID |
c.memory_management.mismatched_memory_management |
Severity |
low |
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. Due to inherent limitations of Semgrep, this rule might generate many false positives and should therefore be customized for your codebase.
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. Due to inherent limitations of Semgrep, this rule might generate many false positives and should therefore be customized for your codebase.
The following code illustrates a vulnerable pattern detected by this rule:
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.