dfu: Free resources on error 84/209484/2 accepted/tizen_5.5_unified accepted/tizen_5.5_unified_mobile_hotfix accepted/tizen_5.5_unified_wearable_hotfix tizen_5.5 tizen_5.5_mobile_hotfix tizen_5.5_tv tizen_5.5_wearable_hotfix accepted/tizen/5.5/unified/20191031.004244 accepted/tizen/5.5/unified/mobile/hotfix/20201027.090327 accepted/tizen/5.5/unified/wearable/hotfix/20201027.113015 accepted/tizen/unified/20190709.071054 submit/tizen/20190708.085020 submit/tizen_5.5/20191031.000010 submit/tizen_5.5_mobile_hotfix/20201026.185104 submit/tizen_5.5_wearable_hotfix/20201026.184304 tizen_5.5.m2_release
authorDongwoo Lee <dwoo08.lee@samsung.com>
Mon, 8 Jul 2019 07:07:45 +0000 (16:07 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Mon, 8 Jul 2019 08:27:09 +0000 (08:27 +0000)
This patch makes resources are freed on error case while scanning
the type of filesystem with blkid APIs. This resource leakage was
reported by static analystic tool.

Change-Id: Ibeba4190316fb1db0bde02eaca0648c0db0bad2e
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
src/dfu.c

index 0131e42..4edf1a1 100644 (file)
--- a/src/dfu.c
+++ b/src/dfu.c
@@ -102,7 +102,7 @@ static char *get_partition_fstype(const char *devname)
        blkid_tag_iterate tag_iter;
        blkid_dev dev;
        blkid_cache cache = NULL;
-       const char *type, *value;
+       const char *type, *value, *fstype = NULL;
        int ret;
 
        ret = blkid_get_cache(&cache, NULL);
@@ -113,29 +113,29 @@ static char *get_partition_fstype(const char *devname)
 
        dev = blkid_get_dev(cache, devname, 0);
        if (!dev)
-               return NULL;
+               goto err_put_cache;
 
        dev = blkid_verify(cache, dev);
        if (!dev)
-               return NULL;
+               goto err_put_cache;
 
        tag_iter = blkid_tag_iterate_begin(dev);
        while (blkid_tag_next(tag_iter, &type, &value) == 0) {
                if (!strncmp(type, "TYPE", 4)) {
-                       char *fstype = strdup(value);
-
+                       fstype = strdup(value);
                        if (!fstype)
-                               return NULL;
+                               fprintf(stderr, "failed to duplicate fs type string\n");
 
-                       blkid_tag_iterate_end(tag_iter);
-                       blkid_put_cache(cache);
-                       return fstype;
+                       break;
                }
        }
+
        blkid_tag_iterate_end(tag_iter);
+
+err_put_cache:
        blkid_put_cache(cache);
 
-       return NULL;
+       return fstype;
 }
 
 static int mount_dev(const char *dev)