]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/GenFv/GenFvInternalLib.c
BaseTools/GenFv: Fix potential memory leak
[mirror_edk2.git] / BaseTools / Source / C / GenFv / GenFvInternalLib.c
index d16b33eee330fcc64078455d5e1bf54589a75efe..bf6b40c4c47050bc3d101d8818257de2556364ed 100644 (file)
@@ -1220,6 +1220,7 @@ Returns:
     if (CompareGuid ((EFI_GUID *) FileBuffer, &mFileGuidArray [Index1]) == 0) {\r
       Error (NULL, 0, 2000, "Invalid parameter", "the %dth file and %uth file have the same file GUID.", (unsigned) Index1 + 1, (unsigned) Index + 1);\r
       PrintGuid ((EFI_GUID *) FileBuffer);\r
+      free (FileBuffer);\r
       return EFI_INVALID_PARAMETER;\r
     }\r
   }\r
@@ -2626,7 +2627,7 @@ Returns:
   //\r
   Status = CalculateFvSize (&mFvDataInfo);\r
   if (EFI_ERROR (Status)) {\r
-    return Status;    \r
+    goto Finish;\r
   }\r
   VerboseMsg ("the generated FV image size is %u bytes", (unsigned) mFvDataInfo.Size);\r
   \r
@@ -2640,7 +2641,8 @@ Returns:
   //\r
   FvBufferHeader = malloc (FvImageSize + sizeof (UINT64));\r
   if (FvBufferHeader == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto Finish;\r
   }\r
   FvImage = (UINT8 *) (((UINTN) FvBufferHeader + 7) & ~7);\r
 \r
@@ -2732,7 +2734,8 @@ Returns:
   FvMapFile = fopen (LongFilePath (FvMapName), "w");\r
   if (FvMapFile == NULL) {\r
     Error (NULL, 0, 0001, "Error opening file", FvMapName);\r
-    return EFI_ABORTED;\r
+    Status = EFI_ABORTED;\r
+    goto Finish;\r
   }\r
   \r
   //\r
@@ -2741,7 +2744,8 @@ Returns:
   FvReportFile = fopen (LongFilePath (FvReportName), "w");\r
   if (FvReportFile == NULL) {\r
     Error (NULL, 0, 0001, "Error opening file", FvReportName);\r
-    return EFI_ABORTED;\r
+    Status = EFI_ABORTED;\r
+    goto Finish;\r
   }\r
   //\r
   // record FV size information into FvMap file.\r
@@ -4259,6 +4263,7 @@ Returns:
 \r
   fwrite (CapBuffer, 1, CapSize, fpout);\r
   fclose (fpout);\r
+  free (CapBuffer);\r
   \r
   VerboseMsg ("The size of the generated capsule image is %u bytes", (unsigned) CapSize);\r
 \r