[2/3] dfu: Fix memory leak in dfu_init_env_entities()

Message ID 20180712215253.4290-2-semen.protsenko@linaro.org
State Superseded
Headers show
Series
  • [1/3] dfu: Fix data abort in dfu_free_entities()
Related show

Commit Message

Sam Protsenko July 12, 2018, 9:52 p.m.
In case of error in dfu_init_env_entities(), env_bkp will leak. Fix it
by providing single return path.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
---
 drivers/dfu/dfu.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Lukasz Majewski July 13, 2018, 9:42 a.m. | #1
Hi Sam,

> In case of error in dfu_init_env_entities(), env_bkp will leak. Fix it

> by providing single return path.

> 

> Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>

> ---

>  drivers/dfu/dfu.c | 7 ++++---

>  1 file changed, 4 insertions(+), 3 deletions(-)

> 

> diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c

> index a3c09334b7..5b9abd685d 100644

> --- a/drivers/dfu/dfu.c

> +++ b/drivers/dfu/dfu.c

> @@ -56,7 +56,7 @@ int dfu_init_env_entities(char *interface, char

> *devstr) {

>  	const char *str_env;

>  	char *env_bkp;

> -	int ret;

> +	int ret = 0;

>  

>  #ifdef CONFIG_SET_DFU_ALT_INFO

>  	set_dfu_alt_info(interface, devstr);

> @@ -71,11 +71,12 @@ int dfu_init_env_entities(char *interface, char

> *devstr) ret = dfu_config_entities(env_bkp, interface, devstr);

>  	if (ret) {

>  		pr_err("DFU entities configuration failed!\n");

> -		return ret;

> +		goto done;

>  	}

>  

> +done:

>  	free(env_bkp);

> -	return 0;

> +	return ret;

>  }

>  

>  static unsigned char *dfu_buf;


Acked-by: Lukasz Majewski <lukma@denx.de>



Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de

Patch

diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c
index a3c09334b7..5b9abd685d 100644
--- a/drivers/dfu/dfu.c
+++ b/drivers/dfu/dfu.c
@@ -56,7 +56,7 @@  int dfu_init_env_entities(char *interface, char *devstr)
 {
 	const char *str_env;
 	char *env_bkp;
-	int ret;
+	int ret = 0;
 
 #ifdef CONFIG_SET_DFU_ALT_INFO
 	set_dfu_alt_info(interface, devstr);
@@ -71,11 +71,12 @@  int dfu_init_env_entities(char *interface, char *devstr)
 	ret = dfu_config_entities(env_bkp, interface, devstr);
 	if (ret) {
 		pr_err("DFU entities configuration failed!\n");
-		return ret;
+		goto done;
 	}
 
+done:
 	free(env_bkp);
-	return 0;
+	return ret;
 }
 
 static unsigned char *dfu_buf;