Hi, Lubo Pls ignore my previous mail. I just checked UEFI spec, it didn't mentioned the GroupTable, RouteTable and IcmpTypeList should be freed by caller. So I think we shouldn't make this change.
Siyuan -----Original Message----- From: Fu, Siyuan Sent: Friday, January 22, 2016 9:26 AM To: Zhang, Lubo <lubo.zh...@intel.com>; edk2-devel@lists.01.org Cc: Ye, Ting <ting...@intel.com>; Wu, Jiaxin <jiaxin...@intel.com> Subject: RE: [patch] MdeModulePkg:Fix Network memory leak when calling GetModeData interface Patch is good to me. Please also update the copyright year when commit it. Reviewed-by: Siyuan Fu <siyuan...@intel.com> -----Original Message----- From: Zhang, Lubo Sent: Thursday, January 21, 2016 10:11 AM To: edk2-devel@lists.01.org Cc: Fu, Siyuan <siyuan...@intel.com>; Ye, Ting <ting...@intel.com>; Wu, Jiaxin <jiaxin...@intel.com> Subject: [patch] MdeModulePkg:Fix Network memory leak when calling GetModeData interface Multiple network protocols have a GetModeData() interface, which may allocate memory resource in the return mode data structure. It's callers responsibility to free these buffers. Cc: Fu Siyuan <siyuan...@intel.com> Cc: Ye Ting <ting...@intel.com> Cc: Wu Jiaxin <jiaxin...@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Zhang Lubo <lubo.zh...@intel.com> --- MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c | 12 ++++++++++++ MdeModulePkg/Universal/Network/Ip4Dxe/ComponentName.c | 14 +++++++++++++- MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDriver.c | 11 +++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c b/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c index cc93c2b..8227283 100644 --- a/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c +++ b/MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c @@ -1764,10 +1764,22 @@ IpIoConfigIp ( &Ip4ModeData, NULL, NULL ); + if (Ip4ModeData.GroupTable != NULL) { + FreePool (Ip4ModeData.GroupTable); + } + + if (Ip4ModeData.RouteTable != NULL) { + FreePool (Ip4ModeData.RouteTable); + } + + if (Ip4ModeData.IcmpTypeList != NULL) { + FreePool (Ip4ModeData.IcmpTypeList); + } + IP4_COPY_ADDRESS (&((EFI_IP4_CONFIG_DATA*) IpConfigData)->StationAddress, &Ip4ModeData.ConfigData.StationAddress); IP4_COPY_ADDRESS (&((EFI_IP4_CONFIG_DATA*) IpConfigData)->SubnetMask, &Ip4ModeData.ConfigData.SubnetMask); } CopyMem ( diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/ComponentName.c b/MdeModulePkg/Universal/Network/Ip4Dxe/ComponentName.c index 2ccfb3c..23af45c 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/ComponentName.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/ComponentName.c @@ -261,11 +261,11 @@ UpdateName ( // Status = Ip4->GetModeData (Ip4, &Ip4ModeData, NULL, NULL); if (EFI_ERROR (Status)) { return Status; } - + if (!Ip4ModeData.IsStarted || !Ip4ModeData.IsConfigured) { UnicodeSPrint (HandleName, sizeof (HandleName), L"IPv4 (Not started)"); } else { UnicodeSPrint (HandleName, sizeof (HandleName), L"IPv4 (SrcIP=%d.%d.%d.%d)", @@ -274,10 +274,22 @@ UpdateName ( Ip4ModeData.ConfigData.StationAddress.Addr[2], Ip4ModeData.ConfigData.StationAddress.Addr[3] ); } + if (Ip4ModeData.GroupTable != NULL) { + FreePool (Ip4ModeData.GroupTable); + } + + if (Ip4ModeData.RouteTable != NULL) { + FreePool (Ip4ModeData.RouteTable); + } + + if (Ip4ModeData.IcmpTypeList != NULL) { + FreePool (Ip4ModeData.IcmpTypeList); } + if (gIp4ControllerNameTable != NULL) { FreeUnicodeStringTable (gIp4ControllerNameTable); gIp4ControllerNameTable = NULL; } Status = AddUnicodeString2 ( diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDriver.c b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDriver.c index 76c140d..bd2530e 100644 --- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDriver.c +++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDriver.c @@ -262,10 +262,21 @@ PxeBcDriverBindingStart ( if (EFI_ERROR (Status)) { goto ON_ERROR; } Private->Ip4MaxPacketSize = Ip4ModeData.MaxPacketSize; + if (Ip4ModeData.GroupTable != NULL) { + FreePool (Ip4ModeData.GroupTable); + } + + if (Ip4ModeData.RouteTable != NULL) { + FreePool (Ip4ModeData.RouteTable); + } + + if (Ip4ModeData.IcmpTypeList != NULL) { + FreePool (Ip4ModeData.IcmpTypeList); } Status = NetLibCreateServiceChild ( ControllerHandle, This->DriverBindingHandle, &gEfiMtftp4ServiceBindingProtocolGuid, -- 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel