When a dynamically allocated block of memory is freed, the memory is usually reallocated to a new data structure in another part of the program. If a program uses a dangling pointer to read values from a recently freed memory block before the freed memory has been reallocated, the expected value might still be present. Although the program appears to work, it could fail if the memory allocation pattern changes and the freed memory block is already reallocated.
In a threaded program, the reallocation can happen in another thread, in which case the failure becomes dependent upon specific timing issues. For example, the program might fail only on a multi-processor machine where the second processor allocates the memory while the first processor is still accessing it.
Similarly, if a program uses a dangling pointer to write a value to a recently freed memory block, the program might continue to work. However, if the memory is already being used by another data structure, the write will corrupt that other data structure. The corruption is apparent only later in the run, when it's difficult to identify the cause.
Purify tracks freed memory and reports invalid memory accesses as Free Memory Read (FMR) or Free Memory Write (FMW) messages. If you use minimal instrumentation, Purify can report a Late Detect Free Memory Write (FMWL) message.
To find out more about catching dangling pointers, click
(C) Copyright IBM Corporation 1992, 2010.