Debugging Dynamic Memory Usage Errors Using HP WDB (5900-1474; WDB 6.2; January 2011)
NOTE: Software literature names this concept as premature free or Reading/writing
freed memory using a pointer.
WDB tracks the dangling pointers and dangling blocks using a modified version of
Garbage collection. The enabler for doing this is by retaining all the freed blocks internally
within RTC without actually freeing it as long as possible. It displays all the potential
pointers to the freed dangling blocks, in the application data space. WDB turns on these
checks, only when you specify set heap-check retain-freed-blocks to on.
The pointers are potential because the pointers need not be actual pointers and could
be a datum value and hence there are chances of false positives in the Dangling report.
NOTE: WDB tries to help as much as possible to detect if these pointers are of type
datum or real pointers. In a -g compiled binary, WDB performs a look-up on a symbol
table to find the symbol name and type to find the symbol name of the potential pointer
and if its of pointer type, then the corresponding dangling block is really dangling (not
a false positive).
Scrambling a Heap Block
The set heap-check scramble <on/off> command enables you to scramble a
heap block and overwrite it with a specific pattern ("0xfeedface") when it is allocated
or de-allocated.
If the application continues to use (read) a freed block (incorrect memory usage), the
application fails to find the expected data in the block. (This means that the data in the
block is different from the initial data that was written in the block.)
This increases the chances of the application to crash or result in unpredictable program
behavior sooner with the unexpected data that is read from the block. Additionally, you
can detect this condition with assertion checks in the code to validate the read data
during the further run of the application.
This command does not detect the corruption. It is only a minimal aid to detect corruption.
Example 14 (page 55) illustrates the scramble feature in WDB.
54