Skip to contentSkip to conversation

dfu: avoid memory leak

PATCH New Peng Fan 3 participants 3 messages May 3, 2016 – May 6, 2016

lore
Share & tools
lore

Peng Fan

author
#0 lore raw

PATCH 1/1 dfu: avoid memory leak

When dfu_fill_entity fail, need to free dfu to avoid memory leak.

Reported by Coverity:
"
Resource leak (RESOURCE_LEAK)
leaked_storage: Variable dfu going out of scope leaks the storage it points to.
"

Cc "?ukasz Majewski" <[email protected]>
Cc Marek Vasut <[email protected]>
---
 drivers/dfu/dfu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/dfu/dfu.c +3 -1
index 8f5915e..20dfcbb 100644
@@ -468,8 +468,10 @@ int dfu_config_entities(char *env, char *interface, char *devstr)
 		s = strsep(&env, ";");
 		ret = dfu_fill_entity(&dfu[i], s, alt_num_cnt, interface,
 				      devstr);
-		if (ret)
+		if (ret) {
+			free(dfu);
 			return -1;
+		}
 
 		list_add_tail(&dfu[i].list, &dfu_list);
 		alt_num_cnt++;
Signature · 1 line
2.6.2
#1 lore raw

PATCH 1/1 dfu: avoid memory leak

Quoted 9 lines · Peng Fan

When dfu_fill_entity fail, need to free dfu to avoid memory leak.

Reported by Coverity:
"
Resource leak (RESOURCE_LEAK)
leaked_storage: Variable dfu going out of scope leaks the storage it points to.
"

Quoted 3 lines
Cc "?ukasz Majewski" <[email protected]>
Cc Marek Vasut <[email protected]>
Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160503/cbfe7f09/attachment.sig>
#2 lore raw

PATCH 1/1 dfu: avoid memory leak

In reply to Peng Fan

Hi Peng,

Quoted 22 lines

When dfu_fill_entity fail, need to free dfu to avoid memory leak.

Reported by Coverity:
"
Resource leak (RESOURCE_LEAK)
leaked_storage: Variable dfu going out of scope leaks the storage it points to.
"

Cc "?ukasz Majewski" <[email protected]>
Cc Marek Vasut <[email protected]>
---
 drivers/dfu/dfu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/dfu/dfu.c +0 -0
index 8f5915e..20dfcbb 100644
@@ -468,8 +468,10 @@ int dfu_config_entities(char *env, char
 *interface, char *devstr) s = strsep(&env, ";");

drivers/dfu/dfu.c int dfu_config_entities(char *env, char · line 477

Quoted 10 lines
drivers/dfu/dfu.c +3 -1
 		ret = dfu_fill_entity(&dfu[i], s, alt_num_cnt,
 interface, devstr);
-		if (ret)
+		if (ret) {
+			free(dfu);
 			return -1;
+		}
 
 		list_add_tail(&dfu[i].list, &dfu_list);
 		alt_num_cnt++;

Applied to u-boot-dfu tree.

Tested-at: Odroid U3 (Exynos4412)

Thanks for running coverity.

Signature · 5 lines
Best regards,

Lukasz Majewski

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