From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=jiaxin.wu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 73F0F21A10965 for ; Tue, 28 Nov 2017 22:47:03 -0800 (PST) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Nov 2017 22:51:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,471,1505804400"; d="scan'208";a="181441289" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by fmsmga005.fm.intel.com with ESMTP; 28 Nov 2017 22:51:26 -0800 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 28 Nov 2017 22:51:26 -0800 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.213]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.159]) with mapi id 14.03.0319.002; Wed, 29 Nov 2017 14:51:17 +0800 From: "Wu, Jiaxin" To: "Wang, Fan" , "edk2-devel@lists.01.org" CC: "Ye, Ting" , "Fu, Siyuan" Thread-Topic: [Patch v2] MdeModulePkg: Free NET_BUF data after it is sent out to avoid memory leak Thread-Index: AQHTZ0s6+lQccuZ3Ck27b0sgzI9E7aMq7Srw Date: Wed, 29 Nov 2017 06:51:16 +0000 Message-ID: <895558F6EA4E3B41AC93A00D163B72741634DAD2@SHSMSX103.ccr.corp.intel.com> References: <1511765030-9008-1-git-send-email-fan.wang@intel.com> In-Reply-To: <1511765030-9008-1-git-send-email-fan.wang@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMDZiMDI2ZDctN2RlZS00ZTA0LTk0MGYtMjdiMjU4YjRkZjNiIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE2LjUuOS4zIiwiVHJ1c3RlZExhYmVsSGFzaCI6IkdIbWNmVnRpNDFJOW5XSVZrcDRmZEZWRmQ5bEFTRDhmb1R3TkUxYjVOQnc9In0= x-ctpclassification: CTP_IC dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [Patch v2] MdeModulePkg: Free NET_BUF data after it is sent out to avoid memory leak X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Nov 2017 06:47:03 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Fan, We need also remove the DhcpReleasePacket() function since no one consume i= t now. Others looks good to me. Thanks, Jiaxin > -----Original Message----- > From: Wang, Fan > Sent: Monday, November 27, 2017 2:44 PM > To: edk2-devel@lists.01.org > Cc: Wu, Jiaxin ; Ye, Ting ; Fu, > Siyuan ; Wang, Fan > Subject: [Patch v2] MdeModulePkg: Free NET_BUF data after it is sent out = to > avoid memory leak >=20 > 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. >=20 > Cc: Jiaxin Wu > Cc: Ye Ting > Cc: Fu Siyuan > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Wang Fan > --- > MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.h | 12 > ++++++++++++ > MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c | 13 +++++------- > - > 2 files changed, 17 insertions(+), 8 deletions(-) >=20 > diff --git a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.h > b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.h > index e546a08..57f6d5e 100644 > --- a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.h > +++ b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.h > @@ -182,10 +182,22 @@ VOID > DhcpCleanConfigure ( > IN OUT EFI_DHCP4_CONFIG_DATA *Config > ); >=20 > /** > + 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 th= e > elapsed time option. >=20 > @param[in] Elapsed The pointer to the position to append. > @param[in] Instance The pointer to the Dhcp4 instance. > diff --git a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c > b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c > index 3898223..54a610a 100644 > --- a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c > +++ b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c > @@ -1357,17 +1357,16 @@ DhcpSendMessage ( > &DhcpSb->ClientAddressSendOut[0], > &Packet->Dhcp4.Header.ClientHwAddr[0], > Packet->Dhcp4.Header.HwAddrLen > ); >=20 > - > // > // Wrap it into a netbuf then send it. > // > Frag.Bulk =3D (UINT8 *) &Packet->Dhcp4.Header; > Frag.Len =3D Packet->Length; > - Wrap =3D NetbufFromExt (&Frag, 1, 0, 0, DhcpReleasePacket, Packet= ); > + Wrap =3D NetbufFromExt (&Frag, 1, 0, 0, DhcpDummyExtFree, NULL); >=20 > if (Wrap =3D=3D NULL) { > FreePool (Packet); > return EFI_OUT_OF_RESOURCES; > } > @@ -1397,11 +1396,10 @@ DhcpSendMessage ( > EndPoint.LocalAddr.Addr[0] =3D DhcpSb->ClientAddr; > UdpIo =3D DhcpSb->LeaseIoPort; > } >=20 > ASSERT (UdpIo !=3D NULL); > - NET_GET_REF (Wrap); >=20 > Status =3D UdpIoSendDatagram ( > UdpIo, > Wrap, > &EndPoint, > @@ -1409,11 +1407,11 @@ DhcpSendMessage ( > DhcpOnPacketSent, > DhcpSb > ); >=20 > if (EFI_ERROR (Status)) { > - NET_PUT_REF (Wrap); > + NetbufFree (Wrap); > return EFI_ACCESS_DENIED; > } >=20 > return EFI_SUCCESS; > } > @@ -1452,16 +1450,16 @@ DhcpRetransmit ( > // > // Wrap it into a netbuf then send it. > // > Frag.Bulk =3D (UINT8 *) &DhcpSb->LastPacket->Dhcp4.Header; > Frag.Len =3D DhcpSb->LastPacket->Length; > - Wrap =3D NetbufFromExt (&Frag, 1, 0, 0, DhcpReleasePacket, DhcpSb= - > >LastPacket); > + Wrap =3D NetbufFromExt (&Frag, 1, 0, 0, DhcpDummyExtFree, NULL); >=20 > if (Wrap =3D=3D NULL) { > return EFI_OUT_OF_RESOURCES; > } > - > + > // > // Broadcast the message, unless we know the server address. > // > EndPoint.RemotePort =3D DHCP_SERVER_PORT; > EndPoint.LocalPort =3D DHCP_CLIENT_PORT; > @@ -1475,22 +1473,21 @@ DhcpRetransmit ( > UdpIo =3D DhcpSb->LeaseIoPort; > } >=20 > ASSERT (UdpIo !=3D NULL); >=20 > - NET_GET_REF (Wrap); > Status =3D UdpIoSendDatagram ( > UdpIo, > Wrap, > &EndPoint, > NULL, > DhcpOnPacketSent, > DhcpSb > ); >=20 > if (EFI_ERROR (Status)) { > - NET_PUT_REF (Wrap); > + NetbufFree (Wrap); > return EFI_ACCESS_DENIED; > } >=20 > return EFI_SUCCESS; > } > -- > 1.9.5.msysgit.1