Debugging Dynamic Memory Usage Errors Using HP WDB
Prerequisites
Following are the prerequisites for debugging memory-related problems in WDB:
• The memory-debugging feature in WDB is dependent on the availability of the dynamic
Linker Version B.11.19.
• WDB uses the heap debugging library, librtc.[sl.so], to enable memory-debugging
support. The librtc.[sl|so] library is a part of the HP WDB product. If the debugger
is installed in a directory other than the default /opt/langtools/bin directory, you must
use the environment variable, LIBRTC_SERVER, to set the path of the appropriate version
of librtc.[sl.so].
• WDB does not support debugging of programs that link with the archive version of the
standard C library, libc.a, or the core library, libcl.a. The programs must be linked
with libc.[sl|so].
• The memory-debugging feature is supported only for programs that directly or indirectly
call malloc(), realloc(), free(), mmap(), or munmap() from the standard C library,
libc.[sl|so], or a third party (custom allocator) implementation of these functions.
• The memory debugging feature is not supported for CMA threaded programs.
• The memory debugging feature cannot be used with applications that re-define or override
the default system-supplied versions of the standard library routines (under libc.so and
libdl.so), such as abort(), strcat(), ctime(), and dlclose(). Before enabling the
memory debugging feature in WDB, use the nm(1) command to determine if the application
or the dependent libraries in the application re-define or substitute the standard library
routines. For more information on the dependent standard library routines, see the HP WDB
release notes, available at the HP WDB Documentation Webpage at:
http://www.hp.com/go/wdb
Memory-Related Errors
This section discusses the following memory-related errors that can occur in an application:
• Heap corruption
• Memory leaks
• Access errors
Heap Corruption
A heap corruption occurs when an application erroneously overwrites some of the data in the
heap. Heap corruption can result in data corruption, memory corruption, or both.
When an application inadvertently uses the erroneously overwritten data in the heap, it results
in data corruption in the application. Data corruption can lead to unpredictable program behavior.
The data corruption in the heap can lead to memory corruption if the corrupted data in the heap
is used by memory management functions in the application to allocate, access, or de-allocate
memory blocks. In other words, memory corruption occurs when the corrupted datum in the
heap is accessed as a pointer. Memory corruptions compromise the data integrity of the application
and can result in segmentation violations if the erroneously allocated or accessed memory blocks
are out of the bounds of the virtual memory of the application.
Causes for Heap Corruption
Following are some of the typical causes for heap corruption:
Double-Free
A double-free error occurs when a program attempts to free a memory block that is already
freed. (Example 16 (page 67) illustrates how WDB detects double-frees.)
Freeing Un-allocated/Un-initialized Memory
Prerequisites 13