public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Jiaxin Wu <jiaxin.wu@intel.com>
To: edk2-devel@lists.01.org
Cc: Ye Ting <ting.ye@intel.com>, Fu Siyuan <siyuan.fu@intel.com>,
	Wang Fan <fan.wang@intel.com>, Wu Jiaxin <jiaxin.wu@intel.com>
Subject: [Patch 2/5] MdeModulePkg/DxeHttpLib: Avoid the potential memory leak when error happen.
Date: Tue, 26 Dec 2017 09:33:46 +0800	[thread overview]
Message-ID: <1514252029-12720-3-git-send-email-jiaxin.wu@intel.com> (raw)
In-Reply-To: <1514252029-12720-1-git-send-email-jiaxin.wu@intel.com>

Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Wang Fan <fan.wang@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
---
 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



  parent reply	other threads:[~2017-12-26  1:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-26  1:33 [Patch 0/5] MdeModulePkg/DxeHttpLib: Fix series issues in DxeHttpLib Jiaxin Wu
2017-12-26  1:33 ` [Patch 1/5] MdeModulePkg/DxeHttpLib: Add boundary condition check Jiaxin Wu
2017-12-26  1:56   ` Gary Lin
2017-12-26  2:21     ` Wu, Jiaxin
2017-12-26  1:33 ` Jiaxin Wu [this message]
2017-12-26  1:33 ` [Patch 3/5] MdeModulePkg/DxeHttpLib: Check the input parameters for some APIs Jiaxin Wu
2017-12-26  1:33 ` [Patch 4/5] MdeModulePkg/DxeHttpLib: Correct some return Status Jiaxin Wu
2017-12-26  1:33 ` [Patch 5/5] MdeModulePkg/DxeHttpLib: Refine some coding style Jiaxin Wu
2017-12-26  1:40 ` [Patch 0/5] MdeModulePkg/DxeHttpLib: Fix series issues in DxeHttpLib Fu, Siyuan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1514252029-12720-3-git-send-email-jiaxin.wu@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox