Skip to contentSkip to conversation

dfu: fix possible memory leak in dfu_init_env_entities()

PATCH New Przemyslaw Marczak 3 participants 3 messages Nov 23, 2015 – Nov 30, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dfu: fix possible memory leak in dfu_init_env_entities()

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.

---
 drivers/dfu/dfu.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/dfu/dfu.c +2 -4
index 8f5915e..420631a 100644
@@ -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;
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 dfu: fix possible memory leak in dfu_init_env_entities()

Quoted 9 lines · Przemyslaw Marczak

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.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151123/7c02a1ec/attachment.sig>
#2 lore raw

PATCH 1/1 dfu: fix possible memory leak in dfu_init_env_entities()

In reply to Przemyslaw Marczak

Hi Przemyslaw,

Quoted 23 lines

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.

---
 drivers/dfu/dfu.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/dfu/dfu.c +1 -1
index 8f5915e..420631a 100644
@@ -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)

drivers/dfu/dfu.c int dfu_init_env_entities(char *interface, char · line 76

Quoted 10 lines
drivers/dfu/dfu.c +1 -3
 		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.

Signature · 5 lines
Best regards,

Lukasz Majewski

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