]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/Dhcp4Dxe: Free NET_BUF data after sent out to avoid memory leak
authorWang Fan <fan.wang@intel.com>
Wed, 10 Jan 2018 07:24:53 +0000 (15:24 +0800)
committerJiaxin Wu <jiaxin.wu@intel.com>
Thu, 11 Jan 2018 00:56:10 +0000 (08:56 +0800)
* When build a DHCP message in function DhcpSendMessage() or DhcpRetransmit(),
a new NET_BUF is created by the library of NetbufFromExt, but it's not freed
after it is sent out. This patch is to fix this memory leak issue.

V2:
* Since packet has already been referred by DhcpSb->LastPacket, and will be
freed when sending another packet or clean up, there is no need to add an
extra free function in NetbufFromExt.

Cc: Jiaxin Wu <jiaxin.wu@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: Wang Fan <fan.wang@intel.com>
Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.h
MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c

index 2d66afe48b65339b51c94aa1e49837b301cba461..ccca4a29af9e5738d091ffcaeea4e0bf65ec40de 100644 (file)
@@ -6,7 +6,7 @@
   RFC 1534: Interoperation Between DHCP and BOOTP\r
   RFC 3396: Encoding Long Options in DHCP.\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
@@ -184,6 +184,18 @@ DhcpCleanConfigure (
   IN OUT EFI_DHCP4_CONFIG_DATA  *Config\r
   );\r
 \r
+/**\r
+  Callback of Dhcp packet. Does nothing.\r
+\r
+  @param Arg           The context.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+DhcpDummyExtFree (\r
+  IN VOID                   *Arg\r
+  );\r
+\r
 /**\r
   Set the elapsed time based on the given instance and the pointer to the\r
   elapsed time option.\r
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