Debugging Dynamic Memory Usage Errors Using HP WDB (766161-001, March 2014)
61 }
62
63
64 void compareStrings()
65 {
66 int s1length, s2length;
67 char *str1 = NULL, *str2 = NULL;
68
69 /* Allocate first string and initialize it */
70 do
71 {
72 printf("Enter length of string 1\n");
73 scanf("%d", & s1length);
74 str1 = createString("String 1", s1length);
75 } while (str1 == NULL);
76
77 /* Allocate second string and initialize it */
78 do
79 {
80 printf("Enter length of string 2\n");
81 scanf("%d", & s2length);
82 str2 = createString("String 2", s2length);
83 } while (str2 == NULL);
84
85 /* Compare strings */
86 if (strcmp(str1, str2))
87 {
88 printf("str1 > str2 \n");
89 }
90 else
91 {
92 printf("str1 <= str2 \n");
93 }
94
95 free(str1);
96 free(str2);
97 }
98
99 int main()
100 {
101 /* Example memory leak program */
102 compareStrings();
103 exit(0);
104 }
105
To detect the memory leak for the test case, complete the following steps:
1. Collect the memory leak report using batch mode.
78