Improper deallocation function causes memory corruption issues
This defect occurs when you use a Windows® deallocation function that is not properly paired to its corresponding allocation function.
Deallocating memory with a function that does not match the allocation function can cause memory corruption or undefined behavior. If you are using an older version of Windows, the improper function can also cause compatibility issues with newer versions.
Properly pair your allocation and deallocation functions according to the functions listed in this table.
| Allocation Function | Deallocation Function |
|---|---|
malloc() | free() |
realloc() | free() |
calloc() | free() |
_aligned_malloc() | _aligned_free() |
_aligned_offset_malloc() | _aligned_free() |
_aligned_realloc() | _aligned_free() |
_aligned_offset_realloc() | _aligned_free() |
_aligned_recalloc() | _aligned_free() |
_aligned_offset_recalloc() | _aligned_free() |
_malloca() | _freea() |
LocalAlloc() | LocalFree() |
LocalReAlloc() | LocalFree() |
GlobalAlloc() | GlobalFree() |
GlobalReAlloc() | GlobalFree() |
VirtualAlloc() | VirtualFree() |
VirtualAllocEx() | VirtualFreeEx() |
VirtualAllocExNuma() | VirtualFreeEx() |
HeapAlloc() | HeapFree() |
HeapReAlloc() | HeapFree() |
| Group: Dynamic memory |
| Language: C | C++ |
| Default: Off |
Command-Line Syntax:
WIN_MISMATCH_DEALLOC
|
| Impact: Low |
| CWE ID: 404, 762 |