From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 2ABE121A00ACF for ; Fri, 23 Jun 2017 02:44:02 -0700 (PDT) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP; 23 Jun 2017 02:45:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,377,1493708400"; d="scan'208";a="118414790" Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.9.2]) by fmsmga006.fm.intel.com with ESMTP; 23 Jun 2017 02:45:26 -0700 From: Star Zeng To: edk2-devel@lists.01.org Cc: Star Zeng , Liming Gao Date: Fri, 23 Jun 2017 17:45:24 +0800 Message-Id: <1498211124-157132-1-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 Subject: [PATCH] MdeModulePkg DxeCore: Only free ScratchBuffer when it is not NULL X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Jun 2017 09:44:02 -0000 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 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng --- MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c b/MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c index 6622eeeaf161..9561ae176655 100644 --- a/MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c +++ b/MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c @@ -27,7 +27,7 @@ 3) A support protocol is not found, and the data is not available to be read without it. This results in EFI_PROTOCOL_ERROR. -Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -1551,7 +1551,9 @@ CustomGuidedSectionExtract ( // AllocatedOutputBuffer = AllocatePool (OutputBufferSize); if (AllocatedOutputBuffer == NULL) { - FreePool (ScratchBuffer); + if (ScratchBuffer != NULL) { + FreePool (ScratchBuffer); + } return EFI_OUT_OF_RESOURCES; } *OutputBuffer = AllocatedOutputBuffer; -- 2.7.0.windows.1