14 Alloc freemem[1000000];
16 char allocStr1[] = "ALLOC";
17 char allocStr2[] = "ALLOC_WC";
18 char freeStr[] = "FREE";
19 char shrbAllocStr1[] = "ALLOC_SHRABL_BUF";
20 char shrbAllocStr2[] = "ALLOC_SHRABL_BUF_WC";
21 char shrbAllocStr3[] = "SHRABL_STATIC_BUF_ALLOC";
22 char shrbFreeStr1[] = "FREE_SHRABL_BUF";
23 char shrbFreeStr2[] = "SHRABL_STATIC_BUF_FREE";
30 /* Open input file pointer */
31 FILE *allocfp=fopen("alloc.txt","r");
32 FILE *freefp=fopen("free.txt","r");
34 /* Open output file pointer */
35 FILE *allocop=fopen("allocoutput.txt","w");
36 FILE *freeop=fopen("freeoutput.txt","w");
38 /* If alloc.txt is open, scan line by line and store "memory size" and
39 * "memory address" in alloc[] structure */
44 while(fgets(buffer, 10000, allocfp))
46 alloc[i].func=malloc(20);
47 alloc[i].add=malloc(20);
48 sscanf(buffer,"%s %d %s", (alloc[i].func), &(alloc[i].size), (alloc[i].add));
49 //printf("%d %s\n",alloc[i].size, alloc[i].add);
54 /* If free.txt is open, scan line by line and store "memory size" and
55 * "memory address" in freemem[] structure */
61 while(fgets(buffer, 10000, freefp))
63 freemem[i].func= malloc(20);
64 freemem[i].add=malloc(20);
65 sscanf(buffer,"%s %d %s", (freemem[i].func), &(freemem[i].size), (freemem[i].add));
66 //printf("%d %s\n",freemem[i].size, freemem[i].add);
71 /* Scan through all entries in alloc[] and freemem[].
72 * If an entry is found in both array, with same size and address, remove this
76 for(count1; count1<allocline; count1++)
78 for(count2=0; count2<freeline; count2++)
80 if(( alloc[count1].size == freemem[count2].size ) &&
81 ( !(strcmp(alloc[count1].add,freemem[count2].add)))
85 (!(strcmp(alloc[count1].func, allocStr1) && strcmp(alloc[count1].func, allocStr2)) && !(strcmp(freemem[count2].func, freeStr))) ||
86 (!(strcmp(alloc[count1].func, shrbAllocStr1) && strcmp(alloc[count1].func, shrbAllocStr2) && strcmp(alloc[count1].func, shrbAllocStr3))\
87 && !(strcmp(freemem[count2].func, shrbFreeStr1) && strcmp(freemem[count2].func, shrbFreeStr2)))
90 //printf("%d %s\n",alloc[count1].size, alloc[count1].add);
91 freemem[count2].size=-1;
92 free(freemem[count2].func);
93 freemem[count2].func = 0;
94 free(freemem[count2].add);
95 freemem[count2].add=0;
97 alloc[count1].size=-1;
98 free(alloc[count1].func);
100 free(alloc[count1].add);
109 if (count2 == freeline)
111 //printf("%d %s\n",alloc[count1].size, alloc[count1].add);
115 /* Add the remaining entries of array[] in allocoutput.txt. These are memory
116 * addresses allocated but not freed */
117 printf("=========== %d %d\n",allocline,freeline);
118 for(count1=0; count1<allocline; count1++)
120 if( (alloc[count1].size!=-1) && (alloc[count1].add !=0) )
122 fprintf(allocop,"%d %s\n",alloc[count1].size, alloc[count1].add);
126 /* Add the remaining entries of freemem[] in freeoutput.txt. These are memory
127 * addresses freed but not allocated */
128 for(count2=0; count2<freeline; count2++)
130 if( (freemem[count2].size!=-1) && (freemem[count2].add !=0) )
132 fprintf(freeop,"%d %s\n",freemem[count2].size, freemem[count2].add);