]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/HttpDxe/HttpImpl.c
NetworkPkg: Avoid memory allocation for each HTTP message exchange.
[mirror_edk2.git] / NetworkPkg / HttpDxe / HttpImpl.c
index dc06b9855c279a801cffc5bf3a59638de05adc72..c5b2be430e29261f7e6eab37585347af95d3e673 100644 (file)
@@ -224,6 +224,7 @@ EfiHttpRequest (
   BOOLEAN                       ReConfigure;\r
   CHAR8                         *RequestStr;\r
   CHAR8                         *Url;\r
+  UINTN                         UrlLen;\r
   CHAR16                        *HostNameStr;\r
   HTTP_TOKEN_WRAP               *Wrap;\r
   HTTP_TCP_TOKEN_WRAP           *TcpWrap;\r
@@ -283,10 +284,15 @@ EfiHttpRequest (
   //\r
   // Parse the URI of the remote host.\r
   //\r
-  Url = AllocatePool (StrLen (Request->Url) + 1);\r
-  if (Url == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
+  UrlLen = StrLen (Request->Url) + 1;\r
+  if (UrlLen > HTTP_URL_BUFFER_LEN) {\r
+    Url = AllocateZeroPool (UrlLen);\r
+    if (Url == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    FreePool (HttpInstance->Url);\r
+    HttpInstance->Url = Url;    \r
+  }  \r
 \r
   UnicodeStrToAsciiStr (Request->Url, Url);\r
   UrlParser = NULL;\r
@@ -347,7 +353,6 @@ EfiHttpRequest (
 \r
         Wrap->TcpWrap.Method = Request->Method;\r
 \r
-        FreePool (Url);\r
         FreePool (HostName);\r
         \r
         //\r
@@ -480,7 +485,6 @@ EfiHttpRequest (
     goto Error4;\r
   }\r
 \r
-  FreePool (Url);\r
   if (HostName != NULL) {\r
     FreePool (HostName);\r
   }\r
@@ -520,9 +524,6 @@ Error2:
   }\r
 \r
 Error1:\r
-  if (Url != NULL) {\r
-    FreePool (Url);\r
-  }\r
   if (HostName != NULL) {\r
     FreePool (HostName);\r
   }\r