[U-Boot] [PATCH] dfu: fix possible memory leak in dfu_init_env_entities()

Lukasz Majewski l.majewski at samsung.com
Mon Nov 30 14:51:09 CET 2015


Hi Przemyslaw,

> The string of environment variable $dfu_alt_info is duplicated
> by strdup() before parsing its content. The memory leak occurs,
> when dfu fails, because the duplicated variable is freed only
> on command success.
> 
> This simple fix allows calling free() always before the return.
> 
> Signed-off-by: Przemyslaw Marczak <p.marczak at samsung.com>
> Cc: Lukasz Majewski <l.majewski at samsung.com>
> ---
>  drivers/dfu/dfu.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c
> index 8f5915e..420631a 100644
> --- a/drivers/dfu/dfu.c
> +++ b/drivers/dfu/dfu.c
> @@ -66,13 +66,11 @@ int dfu_init_env_entities(char *interface, char
> *devstr) 
>  	env_bkp = strdup(str_env);
>  	ret = dfu_config_entities(env_bkp, interface, devstr);
> -	if (ret) {
> +	if (ret)
>  		error("DFU entities configuration failed!\n");
> -		return ret;
> -	}
>  
>  	free(env_bkp);
> -	return 0;
> +	return ret;
>  }
>  
>  static unsigned char *dfu_buf;

Applied to u-boot-dfu branch.

Tested at Odroid XU3 and Trats boards.

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group


More information about the U-Boot mailing list