[edk2] [Patch 1/2] NetworkPkg/HttpBootDxe: Avoid the potential memory leak when eror happen.

Jiaxin Wu posted 2 patches 7 years, 4 months ago
[edk2] [Patch 1/2] NetworkPkg/HttpBootDxe: Avoid the potential memory leak when eror happen.
Posted by Jiaxin Wu 7 years, 4 months ago
Cc: Wang Fan <fan.wang@intel.com>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
---
 NetworkPkg/HttpBootDxe/HttpBootDhcp4.c | 3 +++
 NetworkPkg/HttpBootDxe/HttpBootImpl.c  | 6 +++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/NetworkPkg/HttpBootDxe/HttpBootDhcp4.c b/NetworkPkg/HttpBootDxe/HttpBootDhcp4.c
index a8cee04..421ce6e 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootDhcp4.c
+++ b/NetworkPkg/HttpBootDxe/HttpBootDhcp4.c
@@ -420,10 +420,13 @@ HttpBootParseDhcp4Packet (
 
   } else {
     if (!IsProxyOffer) {
       OfferType = IsDnsOffer ? HttpOfferTypeDhcpDns : HttpOfferTypeDhcpOnly;
     } else {
+      if (Cache4->UriParser != NULL) {
+        FreePool (Cache4->UriParser);
+      }
       return EFI_DEVICE_ERROR;
     }
   }
   
   Cache4->OfferType = OfferType;
diff --git a/NetworkPkg/HttpBootDxe/HttpBootImpl.c b/NetworkPkg/HttpBootDxe/HttpBootImpl.c
index 7f0616d..d4b46a6 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootImpl.c
+++ b/NetworkPkg/HttpBootDxe/HttpBootImpl.c
@@ -120,12 +120,13 @@ HttpBootStart (
   )
 {
   UINTN                Index;
   EFI_STATUS           Status;
   CHAR8                *Uri;
-  
 
+  Uri = NULL;
+  
   if (Private == NULL || FilePath == NULL) {
     return EFI_INVALID_PARAMETER;
   }
   
   //
@@ -152,10 +153,13 @@ HttpBootStart (
       //
       // Restart is required, first stop then continue this start function.
       //
       Status = HttpBootStop (Private);
       if (EFI_ERROR (Status)) {
+        if (Uri != NULL) {
+          FreePool (Uri);
+        }
         return Status;
       }
     } else {
       //
       // Restart is not required.
-- 
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel