]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c
MdeModulePkg/Dhcp4Dxe: Free NET_BUF data after sent out to avoid memory leak
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Dhcp4Dxe / Dhcp4Io.c
index 3898223af5db37d910862e360bcdff9fbd245a14..9532ca8f47efb260d32e3ec550b290aa07d87cb2 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   EFI DHCP protocol implementation.\r
   \r
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -1096,23 +1096,6 @@ RESTART:
   }\r
 }\r
 \r
-\r
-/**\r
-  Release the packet.\r
-\r
-  @param[in]  Arg                   The packet to release\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-DhcpReleasePacket (\r
-  IN VOID                   *Arg\r
-  )\r
-{\r
-  FreePool (Arg);\r
-}\r
-\r
-\r
 /**\r
   Release the net buffer when packet is sent.\r
 \r
@@ -1359,13 +1342,12 @@ DhcpSendMessage (
     Packet->Dhcp4.Header.HwAddrLen\r
     );\r
 \r
-\r
   //\r
   // Wrap it into a netbuf then send it.\r
   //\r
   Frag.Bulk = (UINT8 *) &Packet->Dhcp4.Header;\r
   Frag.Len  = Packet->Length;\r
-  Wrap      = NetbufFromExt (&Frag, 1, 0, 0, DhcpReleasePacket, Packet);\r
+  Wrap      = NetbufFromExt (&Frag, 1, 0, 0, DhcpDummyExtFree, NULL);\r
 \r
   if (Wrap == NULL) {\r
     FreePool (Packet);\r
@@ -1399,7 +1381,6 @@ DhcpSendMessage (
   }\r
 \r
   ASSERT (UdpIo != NULL);\r
-  NET_GET_REF (Wrap);\r
   \r
   Status = UdpIoSendDatagram (\r
              UdpIo, \r
@@ -1411,7 +1392,7 @@ DhcpSendMessage (
              );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    NET_PUT_REF (Wrap);\r
+    NetbufFree (Wrap);\r
     return EFI_ACCESS_DENIED;\r
   }\r
 \r
@@ -1454,12 +1435,12 @@ DhcpRetransmit (
   //\r
   Frag.Bulk = (UINT8 *) &DhcpSb->LastPacket->Dhcp4.Header;\r
   Frag.Len  = DhcpSb->LastPacket->Length;\r
-  Wrap      = NetbufFromExt (&Frag, 1, 0, 0, DhcpReleasePacket, DhcpSb->LastPacket);\r
+  Wrap      = NetbufFromExt (&Frag, 1, 0, 0, DhcpDummyExtFree, NULL);\r
 \r
   if (Wrap == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  \r
+\r
   //\r
   // Broadcast the message, unless we know the server address.\r
   //\r
@@ -1477,7 +1458,6 @@ DhcpRetransmit (
 \r
   ASSERT (UdpIo != NULL);\r
 \r
-  NET_GET_REF (Wrap);\r
   Status = UdpIoSendDatagram (\r
              UdpIo,\r
              Wrap,\r
@@ -1488,7 +1468,7 @@ DhcpRetransmit (
              );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    NET_PUT_REF (Wrap);\r
+    NetbufFree (Wrap);\r
     return EFI_ACCESS_DENIED;\r
   }\r
 \r