]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
cfdisk: fix mem leak and main_menu_action() logic [coverity scan]
authorKarel Zak <kzak@redhat.com>
Wed, 28 Jan 2015 13:30:20 +0000 (14:30 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 28 Jan 2015 13:30:20 +0000 (14:30 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/cfdisk.c

index 647838982789381c96d63724a005fb8ee1883088..9455910f7c64b88970d43d63fe226a658c1169ae 100644 (file)
@@ -1341,13 +1341,15 @@ static int ui_refresh(struct cfdisk *cf)
        struct fdisk_label *lb;
        char *id = NULL;
         uint64_t bytes = fdisk_get_nsectors(cf->cxt) * fdisk_get_sector_size(cf->cxt);
-       char *strsz = size_to_human_string(SIZE_SUFFIX_SPACE
-                               | SIZE_SUFFIX_3LETTER, bytes);
-       erase();
+       char *strsz;
 
+       erase();
        if (!ui_enabled)
                return -EINVAL;
 
+       strsz = size_to_human_string(SIZE_SUFFIX_SPACE
+                               | SIZE_SUFFIX_3LETTER, bytes);
+
        lb = fdisk_get_label(cf->cxt, NULL);
        assert(lb);
 
@@ -1891,6 +1893,8 @@ static int main_menu_action(struct cfdisk *cf, int key)
        }
 
        pa = get_current_partition(cf);
+       if (!pa)
+               return -EINVAL;
        n = fdisk_partition_get_partno(pa);
 
        DBG(MENU, ul_debug("menu action on %p", pa));
@@ -1929,8 +1933,7 @@ static int main_menu_action(struct cfdisk *cf, int key)
                struct fdisk_partition *npa;    /* the new partition */
                int expsize = 0;                /* size specified explicitly in sectors */
 
-               if (!pa || !fdisk_partition_is_freespace(pa)
-                       || !fdisk_partition_has_start(pa))
+               if (!fdisk_partition_is_freespace(pa) || !fdisk_partition_has_start(pa))
                        return -EINVAL;
 
                /* free space range */
@@ -1974,7 +1977,7 @@ static int main_menu_action(struct cfdisk *cf, int key)
        {
                struct fdisk_parttype *t;
 
-               if (!pa || fdisk_partition_is_freespace(pa))
+               if (fdisk_partition_is_freespace(pa))
                        return -EINVAL;
                t = (struct fdisk_parttype *) fdisk_partition_get_type(pa);
                t = ui_get_parttype(cf, t);