BaseTools/TianoCompress: Fix file handles not being closed

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
Hao Wu 2016-10-11 15:56:40 +08:00
parent 1880d5e4d0
commit 4d32be8888
1 changed files with 12 additions and 3 deletions

View File

@ -1764,6 +1764,8 @@ Returns:
InputLength = 0;
InputFileName = NULL;
OutputFileName = NULL;
InputFile = NULL;
OutputFile = NULL;
DstSize=0;
DebugLevel = 0;
DebugMode = FALSE;
@ -1927,9 +1929,6 @@ Returns:
OutputFile = fopen (LongFilePath (OutputFileName), "wb");
if (OutputFile == NULL) {
Error (NULL, 0, 0001, "Error opening output file for writing", OutputFileName);
if (InputFile != NULL) {
fclose (InputFile);
}
goto ERROR;
}
@ -1962,6 +1961,8 @@ Returns:
}
fwrite(OutBuffer,(size_t)DstSize, 1, OutputFile);
fclose(OutputFile);
fclose(InputFile);
free(Scratch);
free(FileBuffer);
free(OutBuffer);
@ -1999,6 +2000,8 @@ Returns:
}
fwrite(OutBuffer, (size_t)(Scratch->mOrigSize), 1, OutputFile);
fclose(OutputFile);
fclose(InputFile);
free(Scratch);
free(FileBuffer);
free(OutBuffer);
@ -2021,6 +2024,12 @@ ERROR:
DebugMsg(UTILITY_NAME, 0, DebugLevel, "Decoding Error\n", NULL);
}
}
if (OutputFile != NULL) {
fclose(OutputFile);
}
if (InputFile != NULL) {
fclose (InputFile);
}
if (Scratch != NULL) {
free(Scratch);
}