Cc: Leif Lindholm <leif.lindh...@linaro.org>
Cc: Ard Biesheuvel <ard.biesheu...@linaro.org>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Paulo Alcantara <paulo.alc.cavalca...@hp.com>
---
 ArmPkg/Library/BdsLib/BdsFilePath.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/ArmPkg/Library/BdsLib/BdsFilePath.c 
b/ArmPkg/Library/BdsLib/BdsFilePath.c
index aefeaed..7667b35 100644
--- a/ArmPkg/Library/BdsLib/BdsFilePath.c
+++ b/ArmPkg/Library/BdsLib/BdsFilePath.c
@@ -126,6 +126,7 @@ BdsGetDeviceUsb (
   for (Index = 0; Index < UsbIoHandleCount; Index++) {
     Status = gBS->HandleProtocol (UsbIoBuffer[Index], 
&gEfiDevicePathProtocolGuid, (VOID **) &UsbIoDevicePath);
     if (!EFI_ERROR (Status)) {
+      Status = EFI_NOT_FOUND;
       TmpDevicePath = UsbIoDevicePath;
       while (!IsDevicePathEnd (TmpDevicePath)) {
         // Check if the Device Path node is a USB Removable device Path node
@@ -140,7 +141,8 @@ BdsGetDeviceUsb (
               *DeviceHandle = UsbIoBuffer[Index];
               // Add the additional original Device Path Nodes (eg: FilePath 
Device Path Node) to the new Device Path
               *NewDevicePath = AppendDevicePath (UsbIoDevicePath, 
NextDevicePathNode (RemovableDevicePath));
-              return EFI_SUCCESS;
+              Status = EFI_SUCCESS;
+              goto Exit;
             }
           } else {
             UsbClassDevicePath1 = (USB_CLASS_DEVICE_PATH*)RemovableDevicePath;
@@ -154,7 +156,8 @@ BdsGetDeviceUsb (
               *DeviceHandle = UsbIoBuffer[Index];
               // Add the additional original Device Path Nodes (eg: FilePath 
Device Path Node) to the new Device Path
               *NewDevicePath = AppendDevicePath (UsbIoDevicePath, 
NextDevicePathNode (RemovableDevicePath));
-              return EFI_SUCCESS;
+              Status = EFI_SUCCESS;
+              goto Exit;
             }
           }
         }
@@ -164,7 +167,9 @@ BdsGetDeviceUsb (
     }
   }
 
-  return EFI_NOT_FOUND;
+Exit:
+  FreePool (UsbIoBuffer);
+  return Status;
 }
 
 BOOLEAN
@@ -202,6 +207,7 @@ BdsGetDeviceHd (
   for (Index = 0; Index < PartitionHandleCount; Index++) {
     Status = gBS->HandleProtocol (PartitionBuffer[Index], 
&gEfiDevicePathProtocolGuid, (VOID **) &PartitionDevicePath);
     if (!EFI_ERROR (Status)) {
+      Status = EFI_NOT_FOUND;
       TmpDevicePath = PartitionDevicePath;
       while (!IsDevicePathEnd (TmpDevicePath)) {
         // Check if the Device Path node is a HD Removable device Path node
@@ -215,7 +221,8 @@ BdsGetDeviceHd (
             *DeviceHandle = PartitionBuffer[Index];
             // Add the additional original Device Path Nodes (eg: FilePath 
Device Path Node) to the new Device Path
             *NewDevicePath = AppendDevicePath (PartitionDevicePath, 
NextDevicePathNode (RemovableDevicePath));
-            return EFI_SUCCESS;
+            Status = EFI_SUCCESS;
+            goto Exit;
           }
         }
         TmpDevicePath = NextDevicePathNode (TmpDevicePath);
@@ -224,7 +231,9 @@ BdsGetDeviceHd (
     }
   }
 
-  return EFI_NOT_FOUND;
+Exit:
+  FreePool (PartitionBuffer);
+  return Status;
 }
 
 /*BOOLEAN
-- 
2.6.2
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to