dfu: avoid memory leak
authorPeng Fan <van.freenix@gmail.com>
Tue, 3 May 2016 02:24:52 +0000 (10:24 +0800)
committerMarek Vasut <marex@denx.de>
Fri, 6 May 2016 18:06:56 +0000 (20:06 +0200)
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.
"

Signed-off-by: Peng Fan <van.freenix@gmail.com>
Cc: "Ɓukasz Majewski" <l.majewski@samsung.com>
Cc: Marek Vasut <marex@denx.de>
drivers/dfu/dfu.c

index 8f5915e49ca5e386f16d4778ef19a6cb0c399088..20dfcbbf18f23a4c2f5ce5fd420ca8881a2ae392 100644 (file)
@@ -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++;