Index: base/applications/cmdutils/comp/comp.c =================================================================== --- base/applications/cmdutils/comp/comp.c (revision 62678) +++ base/applications/cmdutils/comp/comp.c (working copy) @@ -58,7 +58,6 @@ int _tmain (int argc, TCHAR *argv[]) { INT i; - INT LineLen1, LineLen2; FILE *fp1, *fp2; // file pointers PTCHAR Line1 = (TCHAR *)malloc(STRBUF * sizeof(TCHAR)); PTCHAR Line2 = (TCHAR *)malloc(STRBUF * sizeof(TCHAR)); @@ -68,6 +67,13 @@ bAscii = FALSE, // /A switch bLineNos = FALSE; // /L switch + if (Line1 == NULL || + Line2 == NULL) + { + _tprintf(_T("Could not allocate memory required to perform compare\n")); + return EXIT_FAILURE; + } + /* parse command line for options */ for (i = 1; i < argc; i++) { @@ -82,10 +88,14 @@ _tprintf(_T("/l not supported\n")); (void)bLineNos; /*FIXME: needs adding */ break; case '?': Usage(); + free(Line1); + free(Line2); return EXIT_SUCCESS; default: _tprintf(_T("Invalid switch - /%c\n"), argv[i][1]); Usage(); + free(Line1); + free(Line2); return EXIT_FAILURE; } } @@ -135,6 +145,8 @@ break; default : _tprintf(_T("Bad command line syntax\n")); + free(Line1); + free(Line2); return EXIT_FAILURE; break; } @@ -144,6 +156,8 @@ if ((fp1 = fopen(File1, "r")) == NULL) { _tprintf(_T("Can't find/open file: %s\n"), File1); + free(Line1); + free(Line2); return EXIT_FAILURE; } if ((fp2 = fopen(File2, "r")) == NULL) @@ -150,6 +164,8 @@ { _tprintf(_T("Can't find/open file: %s\n"), File2); fclose(fp1); + free(Line1); + free(Line2); return EXIT_FAILURE; } @@ -156,8 +172,8 @@ _tprintf(_T("Comparing %s and %s...\n"), File1, File2); - while ((LineLen1 = GetLine(Line1, fp1) != 0) && - (LineLen2 = GetLine(Line2, fp2) != 0)) + while ((GetLine(Line1, fp1) != 0) && + (GetLine(Line2, fp2) != 0)) { // LineCount++; while ((*Line1 != '\0') && (*Line2 != '\0')) @@ -175,8 +191,9 @@ fclose(fp1); fclose(fp2); + free(Line1); + free(Line2); - return EXIT_SUCCESS; } /* EOF */