Debugging Dynamic Memory Usage Errors Using HP WDB (5900-1474; WDB 6.2; January 2011)

Contents
Introduction.............................................................................................................5
Intended Audience...................................................................................................5
Typographic Conventions...........................................................................................5
Related Information...................................................................................................6
Prerequisites............................................................................................................7
Memory-Related Errors .............................................................................................7
Heap Corruption.................................................................................................8
Causes for Heap Corruption.............................................................................8
Memory Leaks.....................................................................................................8
When to Suspect a Memory Leak?....................................................................9
Types of Memory Leaks....................................................................................9
Access Errors....................................................................................................10
Using WDB to Debug Memory Problems...................................................................10
HP aC++/ HP C Compiler Runtime Checking Options............................................11
Memory Checking Analysis for User Defined Memory Management Routines............12
Memory-Debugging Features of WDB.......................................................................12
Heap Profiling...................................................................................................12
Snapshot Profile ...........................................................................................13
Incremental Heap Profile................................................................................16
Arena Profile................................................................................................20
Analyzing the info heap process output.......................................................22
Analyzing the info heap arenas output........................................................23
Leak Profiling....................................................................................................27
Error Injection ...................................................................................................29
Event Monitoring...............................................................................................35
Monitoring Heap Events ................................................................................35
Monitoring a Specific Address...................................................................36
Monitoring Allocations Greater Than a Specified size...................................38
Monitoring the Program Heap Growth........................................................39
Monitoring Changes in Data Segment Space Allocation (High Water Mark
Feature) .................................................................................................42
Monitoring De-allocations to Detect Double-Frees.........................................45
Monitoring Heap Corruption .........................................................................45
Monitoring String Corruption.....................................................................46
Detecting Out-of-Bounds Writes with the Bounds-Checking Feature..................48
Setting the amount of guard bytes for every block of allocated memory...........50
Detecting Heap Corruption........................................................................50
Detecting dangling pointer and dangling block ...........................................53
Scrambling a Heap Block..........................................................................54
Open-files reporting...........................................................................................55
Settings to Manage Performance Degradation............................................................58
Contents 3