diff mbox series

[U-Boot,1/1] efi_loader: memory leak in efi_set_bootdev()

Message ID 20180916052021.5794-1-xypron.glpk@gmx.de
State Accepted
Commit 79276eb2430d02c84a31fc5613e41aba05429184
Headers show
Series [U-Boot,1/1] efi_loader: memory leak in efi_set_bootdev() | expand

Commit Message

Heinrich Schuchardt Sept. 16, 2018, 5:20 a.m. UTC
efi_set_bootdev() may be called repeatedly.
Free the memory allocated for device paths in previous calls.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 cmd/bootefi.c | 7 +++++++
 1 file changed, 7 insertions(+)
diff mbox series

Patch

diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index 791db359f5..a890f414e8 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -630,6 +630,13 @@  void efi_set_bootdev(const char *dev, const char *devnr, const char *path)
 	char filename[32] = { 0 }; /* dp->str is u16[32] long */
 	char *s;
 
+	/* efi_set_bootdev is typically called repeatedly, recover memory */
+	efi_free_pool(bootefi_device_path);
+	efi_free_pool(bootefi_image_path);
+	/* If blk_get_device_part_str fails, avoid duplicate free. */
+	bootefi_device_path = NULL;
+	bootefi_image_path = NULL;
+
 	if (strcmp(dev, "Net")) {
 		struct blk_desc *desc;
 		disk_partition_t fs_partition;