Dangling Pointers
If you enable memory debugging, TotalView displays information in the Variable Window about the variable’s memory status; that is, whether the memory is allocated or deallocated. The following small program allocates a memory block, sets a pointer to the middle of the block, and then deallocates the block:
main(int argc, char **argv)
{
int *addr = 0; /* Pointer to start of block. */
int *misaddr = 0; /* Pointer to interior of block. */
addr = (int *) malloc (10 * sizeof(int));
misaddr = addr + 5; /* Point to block interior */
/* Deallocate the block. addr and */
/* misaddr are now dangling. */
free (addr);
}
Figure 25 shows two Variable Windows. Execution was stopped before your program executed the free() function. Both windows contain a memory indicator saying that blocks are allocated.
 
Figure 25: Allocated Descriptions in a Variable Window
 
After your program executes the free() function, the messages change, Figure 26.
 
Figure 26: Dangling Description in a Variable Window