Main Content
Mismatched alloc/dealloc functions on Windows
Improper deallocation function causes memory corruption issues
Description
This defect occurs when you use a Windows® deallocation function that is not properly paired to its corresponding allocation function.
Risk
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.
Fix
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() |
Examples
Result Information
Group: Dynamic memory |
Language: C | C++ |
Default: Off |
Command-Line Syntax:
WIN_MISMATCH_DEALLOC
|
Impact: Low |
Version History
Introduced in R2017b
See Also
Invalid deletion of pointer
| Invalid free of pointer
| Find defects (-checkers)
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)