public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] dfu: fix possible memory leak in dfu_init_env_entities()
@ 2015-11-23 15:23 Przemyslaw Marczak
  2015-11-23 15:53 ` Tom Rini
  2015-11-30 13:51 ` Lukasz Majewski
  0 siblings, 2 replies; 3+ messages in thread
From: Przemyslaw Marczak @ 2015-11-23 15:23 UTC (permalink / raw)
  To: u-boot

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@samsung.com>
Cc: Lukasz Majewski <l.majewski@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;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-11-30 13:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-23 15:23 [U-Boot] [PATCH] dfu: fix possible memory leak in dfu_init_env_entities() Przemyslaw Marczak
2015-11-23 15:53 ` Tom Rini
2015-11-30 13:51 ` Lukasz Majewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox