Debugging Dynamic Memory Usage Errors Using HP WDB

Monitoring De-allocations to Detect Double-Frees
The set heap-check free <on/off> command enables you to detect double-frees and
frees with improper arguments.
When this command is enabled, the free() calls are monitored to verify whether the parameters
address valid heap blocks. If an erroneous free() is detected, the debugger stops execution
and reports the error. You can analyze the stack trace to analyze where and how the error occurred.
Example 16 (page 67) illustrates the use of the set heap-check free command.
Monitoring Heap Corruption
WDB enables you to detect the presence of heap-corruption in your application. Table 11 lists
the commands for monitoring heap corruption
Table 11 Commands for Monitoring Heap Corruption
DescriptionCommand
Toggles validation of calls to strcpy(), strncpy(),
memcpy(), memccpy(),memset(), memmove(),
bzero(), and, bcopy()
set heap-check string <on |off>
Toggles the bounds-checking feature for detection of
heap-corruption in WDB
set heap-check bounds <on|off>
Checks for corruption in the currently allocated heap
blocks
info corruption
Scrambles a memory block and overwrites it with a
specific pattern when it is allocated and de-allocated
set heap-check scramble <on | off>
Monitoring String Corruption
The set heap-check string <on/off> command toggles the string corruption detection
feature. It enables you to detect string corruption if functions of the strcpy() family write
out-of-bounds of the allocated memory. Example 11 (page 47)illustrates the use of the set
heap-check string command.
This command currently detects string corruption when writing out-of-bounds for strcpy(),
strncpy(), memcpy(), memccpy(),memset(), memmove(), bzero(), and, bcopy() functions.
46