Free the memory used if an error occurs.

Signed-off-by: Simon Glass <[email protected]>
Suggested-by: Ilias Apalodimas <[email protected]>
---

 lib/efi/efi_app_init.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/efi/efi_app_init.c b/lib/efi/efi_app_init.c
index cc91e1d74b8..fec3f348cfb 100644
--- a/lib/efi/efi_app_init.c
+++ b/lib/efi/efi_app_init.c
@@ -60,8 +60,10 @@ int efi_bind_block(efi_handle_t handle, struct efi_block_io 
*blkio,
        plat->handle = handle;
        plat->blkio = blkio;
        plat->device_path = malloc(device_path_len);
-       if (!plat->device_path)
+       if (!plat->device_path) {
+               free(plat);
                return log_msg_ret("path", -ENOMEM);
+       }
        memcpy(plat->device_path, device_path, device_path_len);
        ret = device_bind(dm_root(), DM_DRIVER_GET(efi_media), "efi_media",
                          plat, ofnode_null(), &dev);
-- 
2.34.1

Reply via email to