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

Przemyslaw Marczak p.marczak at samsung.com
Mon Nov 23 16:23:34 CET 2015


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;
-- 
1.9.1



More information about the U-Boot mailing list