From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=jiaxin.wu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (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 7ABC322225C1A for ; Mon, 25 Dec 2017 17:29:02 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Dec 2017 17:33:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,457,1508828400"; d="scan'208";a="21327532" Received: from jiaxinwu-mobl2.ccr.corp.intel.com ([10.239.196.165]) by orsmga002.jf.intel.com with ESMTP; 25 Dec 2017 17:33:55 -0800 From: Jiaxin Wu To: edk2-devel@lists.01.org Cc: Ye Ting , Fu Siyuan , Wang Fan , Wu Jiaxin Date: Tue, 26 Dec 2017 09:33:46 +0800 Message-Id: <1514252029-12720-3-git-send-email-jiaxin.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1514252029-12720-1-git-send-email-jiaxin.wu@intel.com> References: <1514252029-12720-1-git-send-email-jiaxin.wu@intel.com> Subject: [Patch 2/5] MdeModulePkg/DxeHttpLib: Avoid the potential memory leak when error happen. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Dec 2017 01:29:02 -0000 Cc: Ye Ting Cc: Fu Siyuan Cc: Wang Fan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wu Jiaxin --- MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c index 4d353d7..27b94e3 100644 --- a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c +++ b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c @@ -369,10 +369,12 @@ HttpParseUrl ( UINT32 Field; UINT32 OldField; BOOLEAN FoundAt; EFI_STATUS Status; HTTP_URL_PARSER *Parser; + + Parser = NULL; if (Url == NULL || Length == 0 || UrlParser == NULL) { return EFI_INVALID_PARAMETER; } @@ -399,10 +401,11 @@ HttpParseUrl ( // State = NetHttpParseUrlChar (*Char, State); switch (State) { case UrlParserStateMax: + FreePool (Parser); return EFI_INVALID_PARAMETER; case UrlParserSchemeColon: case UrlParserSchemeColonSlash: case UrlParserSchemeColonSlashSlash: @@ -461,10 +464,11 @@ HttpParseUrl ( // If has authority component, continue to parse the username, host and port. // if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_AUTHORITY)) != 0) { Status = NetHttpParseAuthority (Url, FoundAt, Parser); if (EFI_ERROR (Status)) { + FreePool (Parser); return Status; } } *UrlParser = Parser; @@ -1525,10 +1529,11 @@ HttpSetFieldNameAndValue ( HttpHeader->FieldName[FieldNameSize - 1] = 0; FieldValueSize = AsciiStrSize (FieldValue); HttpHeader->FieldValue = AllocateZeroPool (FieldValueSize); if (HttpHeader->FieldValue == NULL) { + FreePool (HttpHeader->FieldName); return EFI_OUT_OF_RESOURCES; } CopyMem (HttpHeader->FieldValue, FieldValue, FieldValueSize); HttpHeader->FieldValue[FieldValueSize - 1] = 0; -- 1.9.5.msysgit.1