Checking for Dangling Pointers
The pointer checker is not supported on
When dangling pointer checking or heap is enabled, the compiler uses a wrapper for the C runtime function
free()and the C++
operator. These wrappers find all pointers that point to the block being freed, and change their bounds so that any access through the pointer will cause a bound violation. The bounds of these dangling pointers are actually set to:
- lower_bound(p) = 2;
- upper_bound(p) = 0;
If your program gets a bound violation with these bounds, it is the result of a reference through a dangling pointer.
When dangling pointer checking is enabled for stack, the compiler finds all pointers that point to the locals of the function and changes their bounds in the same way as heap pointers above, just before the function exits.
If you have a custom memory allocator, you can enable it to do dangling pointer checking. The
free()function of your custom memory allocator should call this function in the pointer checker runtime code:
void __chkp_invalidate_dangling(void *ptr, size_t size);
This function is declared in theYou must include that header file to use this function because it uses a custom call interface.
You can also enabled dangling pointer checking in any function you use to override the C++