From: Jiaxin Wu Date: Thu, 21 Dec 2017 06:36:12 +0000 (+0800) Subject: MdeModulePkg/DxeHttpLib: Avoid the potential memory leak when error happen. X-Git-Tag: edk2-stable201903~2717 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=f5168b847d8d374fc0206603c7479a3c7ed5fbb0 MdeModulePkg/DxeHttpLib: Avoid the potential memory leak when error happen. Cc: Ye Ting Cc: Fu Siyuan Cc: Wang Fan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wu Jiaxin Reviewed-by: Fu Siyuan --- diff --git a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c index 915b81d17c..774bf7d7e5 100644 --- a/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c +++ b/MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c @@ -372,6 +372,8 @@ HttpParseUrl ( BOOLEAN FoundAt; EFI_STATUS Status; HTTP_URL_PARSER *Parser; + + Parser = NULL; if (Url == NULL || Length == 0 || UrlParser == NULL) { return EFI_INVALID_PARAMETER; @@ -402,6 +404,7 @@ HttpParseUrl ( switch (State) { case UrlParserStateMax: + FreePool (Parser); return EFI_INVALID_PARAMETER; case UrlParserSchemeColon: @@ -464,6 +467,7 @@ HttpParseUrl ( if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_AUTHORITY)) != 0) { Status = NetHttpParseAuthority (Url, FoundAt, Parser); if (EFI_ERROR (Status)) { + FreePool (Parser); return Status; } } @@ -1528,6 +1532,7 @@ HttpSetFieldNameAndValue ( FieldValueSize = AsciiStrSize (FieldValue); HttpHeader->FieldValue = AllocateZeroPool (FieldValueSize); if (HttpHeader->FieldValue == NULL) { + FreePool (HttpHeader->FieldName); return EFI_OUT_OF_RESOURCES; } CopyMem (HttpHeader->FieldValue, FieldValue, FieldValueSize);