dfu: Fix memory leak in dfu_init_env_entities()
authorSam Protsenko <semen.protsenko@linaro.org>
Fri, 13 Jul 2018 13:35:46 +0000 (16:35 +0300)
committerMarek Vasut <marex@denx.de>
Wed, 8 Aug 2018 20:22:08 +0000 (22:22 +0200)
In case of error in dfu_init_env_entities(), env_bkp will leak. Fix it
by providing single return path.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
drivers/dfu/dfu.c

index a3c09334b7b243171994186c2d275b901b406249..5b9abd685d7febee498f466de7bd9be9765a5e8a 100644 (file)
@@ -56,7 +56,7 @@ int dfu_init_env_entities(char *interface, char *devstr)
 {
        const char *str_env;
        char *env_bkp;
-       int ret;
+       int ret = 0;
 
 #ifdef CONFIG_SET_DFU_ALT_INFO
        set_dfu_alt_info(interface, devstr);
@@ -71,11 +71,12 @@ int dfu_init_env_entities(char *interface, char *devstr)
        ret = dfu_config_entities(env_bkp, interface, devstr);
        if (ret) {
                pr_err("DFU entities configuration failed!\n");
-               return ret;
+               goto done;
        }
 
+done:
        free(env_bkp);
-       return 0;
+       return ret;
 }
 
 static unsigned char *dfu_buf;