Debugging Dynamic Memory Usage Errors Using NonStop Native Inspect White Paper
9 {
10 func1(*ptr);
11 }
12 int main()
13
14 {
15 int* han1;
16 printf("Starting program\n");
17 func2(&han1);
18 printf("End of the program\n");
19 }
Sample Debugging Session
(eInspect 1,707): set heap-check on
(eInspect 1,707): b 18
Breakpoint 2 at 0x70000ce0:0: file \PELICAN.$DATA4.USER.EX10C, line 18.
(eInspect 1,707): c
Continuing.
Breakpoint 2, main () at \PELICAN.$DATA4.USER.EX10C:18
* 18 printf("End of the program\n");
(eInspect 1,707): n
* 19 }
(eInspect 1,707): info leak
Scanning for memory leaks...
20 bytes leaked in 1 blocks
No. Total bytes Blocks Address Function
0 20 1 0x0842ad28 func1()
(eInspect 1,707): info leak 0
20 bytes leaked at 0x0842ad28 (100.00% of all bytes leaked)
#0 func1() at \PELICAN.$DATA4.USER.EX10C:5
#1 func2() at \PELICAN.$DATA4.USER.EX10C:11
#2 main() at \PELICAN.$DATA4.USER.EX10C:18
#3 _MAIN() at \SPEEDY.$RLSE.T8432H02.CPLMAINC:46
Example 11 Detecting memory leaks when you free a structure or an array that has
pointers which are not freed
Sample Program
1 #include <stdio.h>
2
3 struct stud
4 {
5 char* name;
6 int id;
7 };
8
9 int main() {
10
11 struct stud *s1;
12 s1 = (struct stud*)malloc(sizeof(struct stud));
13 s1->name = (char*)malloc(50);
14 strcpy(s1,"Annie");
15 s1->id=10;
16 free(s1);
17 }
Sample Debugging Session
(eInspect 1,712): set heap-check on
22










