diff mbox series

bootloader: cboot: fix Resource leak

Message ID 20240204014409.333951-1-m.belouarga@technologyandstrategy.com
State Accepted
Headers show
Series bootloader: cboot: fix Resource leak | expand

Commit Message

Mohamed Belouarga Feb. 4, 2024, 1:44 a.m. UTC
From: BELOUARGA Mohamed <m.belouarga@technologyandstrategy.com>

When a fail occurs, do_apply_list returns -ENOENT without freeing file

Signed-off-by: BELOUARGA Mohamed <m.belouarga@technologyandstrategy.com>
---
 bootloader/cboot.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Stefano Babic Feb. 4, 2024, 6:45 p.m. UTC | #1
On 04.02.24 02:44, belouargamohamed@gmail.com wrote:
> From: BELOUARGA Mohamed <m.belouarga@technologyandstrategy.com>
>
> When a fail occurs, do_apply_list returns -ENOENT without freeing file
>
> Signed-off-by: BELOUARGA Mohamed <m.belouarga@technologyandstrategy.com>
> ---
>   bootloader/cboot.c | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/bootloader/cboot.c b/bootloader/cboot.c
> index 1780e5f..db07639 100644
> --- a/bootloader/cboot.c
> +++ b/bootloader/cboot.c
> @@ -138,6 +138,7 @@ static int do_apply_list(const char *filename)
>   	int result = 0;
>   	if (libcboot.open(BOOTINFO_O_RDWR, &ctx) < 0) {
>   		ERROR("libcboot.open returns with error");
> +		close(file);
>   		return -ENOENT;
>   	}
>   	while ((getline(&line, &length, file)) != -1) {

Reviewed-by: Stefano Babic <stefano.babic@swupdate.org>

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/bootloader/cboot.c b/bootloader/cboot.c
index 1780e5f..db07639 100644
--- a/bootloader/cboot.c
+++ b/bootloader/cboot.c
@@ -138,6 +138,7 @@  static int do_apply_list(const char *filename)
 	int result = 0;
 	if (libcboot.open(BOOTINFO_O_RDWR, &ctx) < 0) {
 		ERROR("libcboot.open returns with error");
+		close(file);
 		return -ENOENT;
 	}
 	while ((getline(&line, &length, file)) != -1) {