]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg DxeCore: Only free ScratchBuffer when it is not NULL
authorStar Zeng <star.zeng@intel.com>
Fri, 23 Jun 2017 09:44:12 +0000 (17:44 +0800)
committerStar Zeng <star.zeng@intel.com>
Mon, 26 Jun 2017 05:17:16 +0000 (13:17 +0800)
There is a case that ExtractGuidedSectionGetInfo return 0 for
ScratchBufferSize and ScratchBuffer will be NULL, after AllocatePool
fails to allocate buffer for AllocatedOutputBuffer, the code will
call FreePool (ScratchBuffer), but ScratchBuffer == NULL.

This patch is to only free ScratchBuffer when it is not NULL.

Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c

index 6622eeeaf1616cf1f76f657b05a31ee7d12498b1..9561ae176655fc4462fafeddf31cc3e076b609b0 100644 (file)
@@ -27,7 +27,7 @@
   3) A support protocol is not found, and the data is not available to be read\r
      without it.  This results in EFI_PROTOCOL_ERROR.\r
 \r
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2017, 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
@@ -1551,7 +1551,9 @@ CustomGuidedSectionExtract (
     //\r
     AllocatedOutputBuffer = AllocatePool (OutputBufferSize);\r
     if (AllocatedOutputBuffer == NULL) {\r
-      FreePool (ScratchBuffer);\r
+      if (ScratchBuffer != NULL) {\r
+        FreePool (ScratchBuffer);\r
+      }\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
     *OutputBuffer = AllocatedOutputBuffer;\r