diff mbox series

[v2] bootstd: Fix a memory leak in the efi manager bootflow

Message ID 20231207123636.26264-1-ilias.apalodimas@linaro.org
State Accepted
Commit eb09c33084ca2106fa669bee402abea4e6e437dd
Headers show
Series [v2] bootstd: Fix a memory leak in the efi manager bootflow | expand

Commit Message

Ilias Apalodimas Dec. 7, 2023, 12:36 p.m. UTC
efi_get_var() allocates memory which has to be freed after the value of
the variable is consumed. Free the memory properly

Fixes: f2bfa0cb1794 ("bootstd: Make efi_mgr bootmeth work for non-sandbox setups")
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
---
Apologies for the quick resend but the previous patches wasn't compiling due to
the missing #include <malloc.h>

Changes since v1
- Add #include <malloc.h> since it's needed for free()

 boot/bootmeth_efi_mgr.c | 2 ++
 1 file changed, 2 insertions(+)

--
2.40.1

Comments

Heinrich Schuchardt Dec. 7, 2023, 2:25 p.m. UTC | #1
On 07.12.23 13:36, Ilias Apalodimas wrote:
> efi_get_var() allocates memory which has to be freed after the value of
> the variable is consumed. Free the memory properly
> 
> Fixes: f2bfa0cb1794 ("bootstd: Make efi_mgr bootmeth work for non-sandbox setups")
> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

> ---
> Apologies for the quick resend but the previous patches wasn't compiling due to
> the missing #include <malloc.h>
> 
> Changes since v1
> - Add #include <malloc.h> since it's needed for free()
> 
>   boot/bootmeth_efi_mgr.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/boot/bootmeth_efi_mgr.c b/boot/bootmeth_efi_mgr.c
> index e6c42d41fb80..6428c096d7f8 100644
> --- a/boot/bootmeth_efi_mgr.c
> +++ b/boot/bootmeth_efi_mgr.c
> @@ -16,6 +16,7 @@
>   #include <dm.h>
>   #include <efi_loader.h>
>   #include <efi_variable.h>
> +#include <malloc.h>
> 
>   /**
>    * struct efi_mgr_priv - private info for the efi-mgr driver
> @@ -65,6 +66,7 @@ static int efi_mgr_read_bootflow(struct udevice *dev, struct bootflow *bflow)
>   	bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid,
>   				&size);
>   	if (bootorder) {
> +		free(bootorder);
>   		bflow->state = BOOTFLOWST_READY;
>   		return 0;
>   	}
> --
> 2.40.1
>
Mark Kettenis Dec. 7, 2023, 4:54 p.m. UTC | #2
> From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> Date: Thu,  7 Dec 2023 14:36:36 +0200
> 
> efi_get_var() allocates memory which has to be freed after the value of
> the variable is consumed. Free the memory properly
> 
> Fixes: f2bfa0cb1794 ("bootstd: Make efi_mgr bootmeth work for non-sandbox setups")
> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> ---
> Apologies for the quick resend but the previous patches wasn't compiling due to
> the missing #include <malloc.h>
> 
> Changes since v1
> - Add #include <malloc.h> since it's needed for free()
> 
>  boot/bootmeth_efi_mgr.c | 2 ++
>  1 file changed, 2 insertions(+)

Oops!

Reviewed-by: Mark Kettenis <kettenis@openbsd.org>

> diff --git a/boot/bootmeth_efi_mgr.c b/boot/bootmeth_efi_mgr.c
> index e6c42d41fb80..6428c096d7f8 100644
> --- a/boot/bootmeth_efi_mgr.c
> +++ b/boot/bootmeth_efi_mgr.c
> @@ -16,6 +16,7 @@
>  #include <dm.h>
>  #include <efi_loader.h>
>  #include <efi_variable.h>
> +#include <malloc.h>
> 
>  /**
>   * struct efi_mgr_priv - private info for the efi-mgr driver
> @@ -65,6 +66,7 @@ static int efi_mgr_read_bootflow(struct udevice *dev, struct bootflow *bflow)
>  	bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid,
>  				&size);
>  	if (bootorder) {
> +		free(bootorder);
>  		bflow->state = BOOTFLOWST_READY;
>  		return 0;
>  	}
> --
> 2.40.1
> 
>
Simon Glass Dec. 13, 2023, 8:38 p.m. UTC | #3
> From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> Date: Thu,  7 Dec 2023 14:36:36 +0200
>
> efi_get_var() allocates memory which has to be freed after the value of
> the variable is consumed. Free the memory properly
>
> Fixes: f2bfa0cb1794 ("bootstd: Make efi_mgr bootmeth work for non-sandbox setups")
> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> ---
> Apologies for the quick resend but the previous patches wasn't compiling due to
> the missing #include <malloc.h>
>
> Changes since v1
> - Add #include <malloc.h> since it's needed for free()
>
>  boot/bootmeth_efi_mgr.c | 2 ++
>  1 file changed, 2 insertions(+)

Oops!

Reviewed-by: Mark Kettenis <kettenis@openbsd.org>

Applied to u-boot-dm/next, thanks!
diff mbox series

Patch

diff --git a/boot/bootmeth_efi_mgr.c b/boot/bootmeth_efi_mgr.c
index e6c42d41fb80..6428c096d7f8 100644
--- a/boot/bootmeth_efi_mgr.c
+++ b/boot/bootmeth_efi_mgr.c
@@ -16,6 +16,7 @@ 
 #include <dm.h>
 #include <efi_loader.h>
 #include <efi_variable.h>
+#include <malloc.h>

 /**
  * struct efi_mgr_priv - private info for the efi-mgr driver
@@ -65,6 +66,7 @@  static int efi_mgr_read_bootflow(struct udevice *dev, struct bootflow *bflow)
 	bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid,
 				&size);
 	if (bootorder) {
+		free(bootorder);
 		bflow->state = BOOTFLOWST_READY;
 		return 0;
 	}