]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/C/Common: Fix potential memory leak
authorHao Wu <hao.a.wu@intel.com>
Wed, 28 Sep 2016 03:18:12 +0000 (11:18 +0800)
committerHao Wu <hao.a.wu@intel.com>
Tue, 8 Nov 2016 08:37:28 +0000 (16:37 +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/Common/Decompress.c
BaseTools/Source/C/Common/FirmwareVolumeBuffer.c
BaseTools/Source/C/Common/MemoryFile.c
BaseTools/Source/C/Common/ParseGuidedSectionTools.c

index 77df89ff48cba2a3756578ac7080037d6b927ed0..4b83e88210e14b89ff4ec704f5b6385dcad7c54b 100644 (file)
@@ -934,7 +934,9 @@ Extract (
   UINT32        ScratchSize;\r
   EFI_STATUS    Status;\r
 \r
-  Status = EFI_SUCCESS;\r
+  Scratch = NULL;\r
+  Status  = EFI_SUCCESS;\r
+\r
   switch (Algorithm) {\r
   case 0:\r
     *Destination = (VOID *)malloc(SrcSize);\r
@@ -948,30 +950,44 @@ Extract (
     Status = EfiGetInfo(Source, SrcSize, DstSize, &ScratchSize);\r
     if (Status == EFI_SUCCESS) {\r
       Scratch = (VOID *)malloc(ScratchSize);\r
+      if (Scratch == NULL) {\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+\r
       *Destination = (VOID *)malloc(*DstSize);\r
-      if (Scratch != NULL && *Destination != NULL) {\r
-        Status = EfiDecompress(Source, SrcSize, *Destination, *DstSize, Scratch, ScratchSize);\r
-      } else {\r
-        Status = EFI_OUT_OF_RESOURCES;\r
+      if (*Destination == NULL) {\r
+        free (Scratch);\r
+        return EFI_OUT_OF_RESOURCES;\r
       }\r
+\r
+      Status = EfiDecompress(Source, SrcSize, *Destination, *DstSize, Scratch, ScratchSize);\r
     }\r
     break;\r
   case 2:\r
     Status = TianoGetInfo(Source, SrcSize, DstSize, &ScratchSize);\r
     if (Status == EFI_SUCCESS) {\r
       Scratch = (VOID *)malloc(ScratchSize);\r
+      if (Scratch == NULL) {\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+\r
       *Destination = (VOID *)malloc(*DstSize);\r
-      if (Scratch != NULL && *Destination != NULL) {\r
-        Status = TianoDecompress(Source, SrcSize, *Destination, *DstSize, Scratch, ScratchSize);\r
-      } else {\r
-        Status = EFI_OUT_OF_RESOURCES;\r
+      if (*Destination == NULL) {\r
+        free (Scratch);\r
+        return EFI_OUT_OF_RESOURCES;\r
       }\r
+\r
+      Status = TianoDecompress(Source, SrcSize, *Destination, *DstSize, Scratch, ScratchSize);\r
     }\r
     break;\r
   default:\r
     Status = EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  if (Scratch != NULL) {\r
+    free (Scratch);\r
+  }\r
+\r
   return Status;\r
 }\r
 \r
index a287fe1597a64c9e7ca9538b6714c12056e43d03..d4a635335a6e3ffbb47012d577f85d9216a1995a 100644 (file)
@@ -186,6 +186,7 @@ Returns:
 \r
   Status = FvBufClearAllFiles (TempFv);\r
   if (EFI_ERROR (Status)) {\r
+    CommonLibBinderFree (TempFv);\r
     return Status;\r
   }\r
 \r
index 00ea0c615b7a2a01b4ad9aeb26f86af8a3ba2fc2..1d9068822ef40ecf6380f6335e41ebb8a119c993 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 This contains some useful functions for accessing files.\r
 \r
-Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials                          \r
 are licensed and made available under the terms and conditions of the BSD License         \r
 which accompanies this distribution.  The full text of the license may be found at        \r
@@ -69,6 +69,7 @@ Returns:
 \r
   NewMemoryFile = malloc (sizeof (*NewMemoryFile));\r
   if (NewMemoryFile == NULL) {\r
+    free (InputFileImage);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
index fc8f488f7e46e646c30a62b6e9a305bcc7c90077..115cfa41439f7b0b6cebe510ef6f45ef5d30c320 100644 (file)
@@ -125,10 +125,12 @@ Returns:
     \r
     Status = StripInfDscStringInPlace (NextLine);\r
     if (EFI_ERROR (Status)) {\r
+      free (NextLine);\r
       break;\r
     }\r
 \r
     if (NextLine[0] == '\0') {\r
+      free (NextLine);\r
       continue;\r
     }\r
 \r
@@ -153,8 +155,12 @@ Returns:
           LastGuidTool = NewGuidTool;\r
         }\r
       }\r
+    }\r
+\r
+    if (Tool != NULL) {\r
       FreeStringList (Tool);\r
     }\r
+    free (NextLine);\r
   }\r
 \r
   return FirstGuidTool;\r