summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWang Fan <fan.wang@intel.com>2018-01-10 15:24:53 +0800
committerJiaxin Wu <jiaxin.wu@intel.com>2018-01-11 08:56:10 +0800
commit479a3b6053bb4c508d7397c65f482e0a8f3c9719 (patch)
tree6515365ed083413294f53d9b4075846e6f9209eb
parent427b2f41a6e21140fde1ccd900ed228de672ce33 (diff)
downloadedk2-479a3b6053bb4c508d7397c65f482e0a8f3c9719.tar.gz
edk2-479a3b6053bb4c508d7397c65f482e0a8f3c9719.tar.bz2
edk2-479a3b6053bb4c508d7397c65f482e0a8f3c9719.zip
MdeModulePkg/Dhcp4Dxe: Free NET_BUF data after sent out to avoid memory leak
* 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>
-rw-r--r--MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.h14
-rw-r--r--MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c32
2 files changed, 19 insertions, 27 deletions
diff --git a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.h b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.h
index 2d66afe48b..ccca4a29af 100644
--- a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.h
+++ b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.h
@@ -6,7 +6,7 @@
RFC 1534: Interoperation Between DHCP and BOOTP
RFC 3396: Encoding Long Options in DHCP.
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -185,6 +185,18 @@ DhcpCleanConfigure (
);
/**
+ Callback of Dhcp packet. Does nothing.
+
+ @param Arg The context.
+
+**/
+VOID
+EFIAPI
+DhcpDummyExtFree (
+ IN VOID *Arg
+ );
+
+/**
Set the elapsed time based on the given instance and the pointer to the
elapsed time option.
diff --git a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c
index 3898223af5..9532ca8f47 100644
--- a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c
+++ b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c
@@ -1,7 +1,7 @@
/** @file
EFI DHCP protocol implementation.
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -1096,23 +1096,6 @@ RESTART:
}
}
-
-/**
- Release the packet.
-
- @param[in] Arg The packet to release
-
-**/
-VOID
-EFIAPI
-DhcpReleasePacket (
- IN VOID *Arg
- )
-{
- FreePool (Arg);
-}
-
-
/**
Release the net buffer when packet is sent.
@@ -1359,13 +1342,12 @@ DhcpSendMessage (
Packet->Dhcp4.Header.HwAddrLen
);
-
//
// Wrap it into a netbuf then send it.
//
Frag.Bulk = (UINT8 *) &Packet->Dhcp4.Header;
Frag.Len = Packet->Length;
- Wrap = NetbufFromExt (&Frag, 1, 0, 0, DhcpReleasePacket, Packet);
+ Wrap = NetbufFromExt (&Frag, 1, 0, 0, DhcpDummyExtFree, NULL);
if (Wrap == NULL) {
FreePool (Packet);
@@ -1399,7 +1381,6 @@ DhcpSendMessage (
}
ASSERT (UdpIo != NULL);
- NET_GET_REF (Wrap);
Status = UdpIoSendDatagram (
UdpIo,
@@ -1411,7 +1392,7 @@ DhcpSendMessage (
);
if (EFI_ERROR (Status)) {
- NET_PUT_REF (Wrap);
+ NetbufFree (Wrap);
return EFI_ACCESS_DENIED;
}
@@ -1454,12 +1435,12 @@ DhcpRetransmit (
//
Frag.Bulk = (UINT8 *) &DhcpSb->LastPacket->Dhcp4.Header;
Frag.Len = DhcpSb->LastPacket->Length;
- Wrap = NetbufFromExt (&Frag, 1, 0, 0, DhcpReleasePacket, DhcpSb->LastPacket);
+ Wrap = NetbufFromExt (&Frag, 1, 0, 0, DhcpDummyExtFree, NULL);
if (Wrap == NULL) {
return EFI_OUT_OF_RESOURCES;
}
-
+
//
// Broadcast the message, unless we know the server address.
//
@@ -1477,7 +1458,6 @@ DhcpRetransmit (
ASSERT (UdpIo != NULL);
- NET_GET_REF (Wrap);
Status = UdpIoSendDatagram (
UdpIo,
Wrap,
@@ -1488,7 +1468,7 @@ DhcpRetransmit (
);
if (EFI_ERROR (Status)) {
- NET_PUT_REF (Wrap);
+ NetbufFree (Wrap);
return EFI_ACCESS_DENIED;
}