From: Hao Wu Date: Tue, 11 Oct 2016 07:56:40 +0000 (+0800) Subject: BaseTools/TianoCompress: Fix file handles not being closed X-Git-Tag: edk2-stable201903~5306 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=4d32be8888f4b7d8e337259fe1a5afd71b6b0046 BaseTools/TianoCompress: Fix file handles not being closed Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu Reviewed-by: Liming Gao --- diff --git a/BaseTools/Source/C/TianoCompress/TianoCompress.c b/BaseTools/Source/C/TianoCompress/TianoCompress.c index 44dbccf9ad..f810511f5f 100644 --- a/BaseTools/Source/C/TianoCompress/TianoCompress.c +++ b/BaseTools/Source/C/TianoCompress/TianoCompress.c @@ -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); }