Dangling pointers

Dangling pointers are pointers that have had memory freed but which have not been set to null. It is often possible for subsequent code to keep on using the dangling pointer and to keep on getting valid-looking data until that memory is suddenly repurposed for something else.

This leads to unpredictable behavior, silent corruption and program crashes.

To enable detection of dangling pointers, the memory debugging settings must be set to one level higher than Fast. The term free-protect appears in the Enabled Checks window.

This level of memory debugging is usually all you need to find dangling pointer problems. When a dangling pointer is reused, DDT stops your program at the exact line of code that reuses it, with an error like this one:



The debugger also shows which pointer is dangling and exactly where it was originally allocated. Right-click on any pointers or dynamically-allocated arrays and choose View Pointer Details from the menu:



Arm DDT immediately indicates that this pointer is dangling (it indicates that the pointer points to an allocation that has already been freed) and shows the full stack of function calls that led to its allocation.

Previous Next