From fa461abf8a51b09c965d15c0d65be704b8b00a19 Mon Sep 17 00:00:00 2001 From: Qihang Gao Date: Thu, 25 Jun 2026 17:07:51 +0800 Subject: [PATCH] MdePkg/UefiDevicePathLib: Fix the potential memory leak issue The function DevPathToTextUsbWWID() allocates NewStr when the input SerialNumber lacks a null terminator. However, this allocated memory is never freed after use, resulting in a memory leak. This patch adds the missing FreePool() for NewStr before the function returns, ensuring that the allocated buffer is properly freed and eliminating the potential leak. Signed-off-by: Qihang Gao --- MdePkg/Library/UefiDevicePathLib/DevicePathToText.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c index b0d5829e05..4b7ca27d01 100644 --- a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c @@ -996,6 +996,7 @@ DevPathToTextUsbWWID ( UINT16 Length; UsbWWId = DevPath; + NewStr = NULL; SerialNumberStr = (CHAR16 *)((UINT8 *)UsbWWId + sizeof (USB_WWID_DEVICE_PATH)); Length = (UINT16)((DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *)UsbWWId) - sizeof (USB_WWID_DEVICE_PATH)) / sizeof (CHAR16)); @@ -1018,6 +1019,10 @@ DevPathToTextUsbWWID ( UsbWWId->InterfaceNumber, SerialNumberStr ); + + if (NewStr != NULL) { + FreePool (NewStr); + } } /**