]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/GenVtf: Fix file handles not being closed
authorHao Wu <hao.a.wu@intel.com>
Tue, 11 Oct 2016 07:50:10 +0000 (15:50 +0800)
committerHao Wu <hao.a.wu@intel.com>
Tue, 8 Nov 2016 08:38:05 +0000 (16:38 +0800)
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>
BaseTools/Source/C/GenVtf/GenVtf.c

index a61502f3151e9ede3428ba49951fea1bfa2a891d..c37122c853fd8e5cb1c9ed5622e537f1b594b453 100644 (file)
@@ -1164,6 +1164,7 @@ Returns:
 \r
   if (VtfInfo->PreferredSize) {\r
     if (FileSize > VtfInfo->CompSize) {\r
 \r
   if (VtfInfo->PreferredSize) {\r
     if (FileSize > VtfInfo->CompSize) {\r
+      fclose (Fp);\r
       Error (NULL, 0, 2000, "Invalid parameter", "The component size is more than specified size.");\r
       return EFI_ABORTED;\r
     }\r
       Error (NULL, 0, 2000, "Invalid parameter", "The component size is more than specified size.");\r
       return EFI_ABORTED;\r
     }\r
@@ -1173,6 +1174,7 @@ Returns:
 \r
   Buffer = malloc ((UINTN) FileSize);\r
   if (Buffer == NULL) {\r
 \r
   Buffer = malloc ((UINTN) FileSize);\r
   if (Buffer == NULL) {\r
+    fclose (Fp);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
   memset (Buffer, 0, (UINTN) FileSize);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
   memset (Buffer, 0, (UINTN) FileSize);\r
@@ -1342,6 +1344,7 @@ Returns:
 \r
   FileSize = _filelength (fileno (Fp));\r
   if (FileSize < 64) {\r
 \r
   FileSize = _filelength (fileno (Fp));\r
   if (FileSize < 64) {\r
+    fclose (Fp);\r
     Error (NULL, 0, 2000, "Invalid parameter", "PAL_A bin header is 64 bytes, so the Bin size must be larger than 64 bytes!");\r
     return EFI_INVALID_PARAMETER;\r
   }\r
     Error (NULL, 0, 2000, "Invalid parameter", "PAL_A bin header is 64 bytes, so the Bin size must be larger than 64 bytes!");\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -1350,6 +1353,7 @@ Returns:
 \r
   if (VtfInfo->PreferredSize) {\r
     if (FileSize > VtfInfo->CompSize) {\r
 \r
   if (VtfInfo->PreferredSize) {\r
     if (FileSize > VtfInfo->CompSize) {\r
+      fclose (Fp);\r
       Error (NULL, 0, 2000, "Invalid parameter", "The PAL_A Size is more than the specified size.");\r
       return EFI_ABORTED;\r
     }\r
       Error (NULL, 0, 2000, "Invalid parameter", "The PAL_A Size is more than the specified size.");\r
       return EFI_ABORTED;\r
     }\r
@@ -1359,6 +1363,7 @@ Returns:
 \r
   Buffer = malloc ((UINTN) FileSize);\r
   if (Buffer == NULL) {\r
 \r
   Buffer = malloc ((UINTN) FileSize);\r
   if (Buffer == NULL) {\r
+    fclose (Fp);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
   memset (Buffer, 0, (UINTN) FileSize);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
   memset (Buffer, 0, (UINTN) FileSize);\r
@@ -1775,11 +1780,13 @@ Returns:
   FileSize = _filelength (fileno (Fp));\r
 \r
   if (FileSize > 16) {\r
   FileSize = _filelength (fileno (Fp));\r
 \r
   if (FileSize > 16) {\r
+    fclose (Fp);\r
     return EFI_ABORTED;\r
   }\r
 \r
   Buffer = malloc (FileSize);\r
   if (Buffer == NULL) {\r
     return EFI_ABORTED;\r
   }\r
 \r
   Buffer = malloc (FileSize);\r
   if (Buffer == NULL) {\r
+    fclose (Fp);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
@@ -2548,6 +2555,12 @@ Returns:
       // Get the input VTF file name\r
       //\r
       VtfFileName = argv[Index+1];\r
       // Get the input VTF file name\r
       //\r
       VtfFileName = argv[Index+1];\r
+      if (VtfFP != NULL) {\r
+        //\r
+        // VTF file name has been given previously, override with the new value\r
+        //\r
+        fclose (VtfFP);\r
+      }\r
       VtfFP = fopen (LongFilePath (VtfFileName), "rb");\r
       if (VtfFP == NULL) {\r
         Error (NULL, 0, 0001, "Error opening file", VtfFileName);\r
       VtfFP = fopen (LongFilePath (VtfFileName), "rb");\r
       if (VtfFP == NULL) {\r
         Error (NULL, 0, 0001, "Error opening file", VtfFileName);\r