Author: pschweitzer Date: Tue Sep 20 12:29:47 2011 New Revision: 53770
URL: http://svn.reactos.org/svn/reactos?rev=53770&view=rev Log: [OBJ2BIN] - Fix memory leaks - Fix resources leaks - Fix wrong if statement
Modified: trunk/reactos/tools/obj2bin/obj2bin.c
Modified: trunk/reactos/tools/obj2bin/obj2bin.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/obj2bin/obj2bin.c?rev... ============================================================================== --- trunk/reactos/tools/obj2bin/obj2bin.c [iso-8859-1] (original) +++ trunk/reactos/tools/obj2bin/obj2bin.c [iso-8859-1] Tue Sep 20 12:29:47 2011 @@ -97,6 +97,7 @@ pData = malloc(nFileSize); if (!pData) { + fclose(pSourceFile); fprintf(stderr, "Failed to allocate %ld bytes\n", nFileSize); return -3; } @@ -104,6 +105,8 @@ /* Read the whole source file */ if (!fread(pData, nFileSize, 1, pSourceFile)) { + free(pData); + fclose(pSourceFile); fprintf(stderr, "Failed to read source file: %ld\n", nFileSize); return -4; } @@ -113,8 +116,9 @@
/* Open the destination file */ pDestFile = fopen(pszDestFile, "wb"); - if (!pszDestFile) + if (!pDestFile) { + free(pData); fprintf(stderr, "Couldn't open dest file '%s'\n", pszDestFile); return -5; } @@ -140,6 +144,8 @@ if (!fwrite(pData + pSectionHeader->PointerToRawData, pSectionHeader->SizeOfRawData, 1, pDestFile)) { + free(pData); + fclose(pDestFile); fprintf(stderr, "Failed to write data %ld\n", pSectionHeader->SizeOfRawData); return -6; @@ -151,6 +157,7 @@ pSectionHeader++; }
+ free(pData); fclose(pDestFile);
return 0;