[OBJ2BIN]

- Fix memory leaks
- Fix resources leaks
- Fix wrong if statement

svn path=/trunk/; revision=53770
This commit is contained in:
Pierre Schweitzer 2011-09-20 12:29:47 +00:00
parent daf0243ef5
commit 06fd95c89b

View file

@ -97,6 +97,7 @@ int main(int argc, char *argv[])
pData = malloc(nFileSize); pData = malloc(nFileSize);
if (!pData) if (!pData)
{ {
fclose(pSourceFile);
fprintf(stderr, "Failed to allocate %ld bytes\n", nFileSize); fprintf(stderr, "Failed to allocate %ld bytes\n", nFileSize);
return -3; return -3;
} }
@ -104,6 +105,8 @@ int main(int argc, char *argv[])
/* Read the whole source file */ /* Read the whole source file */
if (!fread(pData, nFileSize, 1, pSourceFile)) if (!fread(pData, nFileSize, 1, pSourceFile))
{ {
free(pData);
fclose(pSourceFile);
fprintf(stderr, "Failed to read source file: %ld\n", nFileSize); fprintf(stderr, "Failed to read source file: %ld\n", nFileSize);
return -4; return -4;
} }
@ -113,8 +116,9 @@ int main(int argc, char *argv[])
/* Open the destination file */ /* Open the destination file */
pDestFile = fopen(pszDestFile, "wb"); pDestFile = fopen(pszDestFile, "wb");
if (!pszDestFile) if (!pDestFile)
{ {
free(pData);
fprintf(stderr, "Couldn't open dest file '%s'\n", pszDestFile); fprintf(stderr, "Couldn't open dest file '%s'\n", pszDestFile);
return -5; return -5;
} }
@ -140,6 +144,8 @@ int main(int argc, char *argv[])
if (!fwrite(pData + pSectionHeader->PointerToRawData, if (!fwrite(pData + pSectionHeader->PointerToRawData,
pSectionHeader->SizeOfRawData, 1, pDestFile)) pSectionHeader->SizeOfRawData, 1, pDestFile))
{ {
free(pData);
fclose(pDestFile);
fprintf(stderr, "Failed to write data %ld\n", fprintf(stderr, "Failed to write data %ld\n",
pSectionHeader->SizeOfRawData); pSectionHeader->SizeOfRawData);
return -6; return -6;
@ -151,6 +157,7 @@ int main(int argc, char *argv[])
pSectionHeader++; pSectionHeader++;
} }
free(pData);
fclose(pDestFile); fclose(pDestFile);
return 0; return 0;