From: Karel Zak Date: Wed, 28 Jan 2015 13:30:20 +0000 (+0100) Subject: cfdisk: fix mem leak and main_menu_action() logic [coverity scan] X-Git-Tag: v2.26-rc2~62 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ec8a728ae0f62c2ae4870548754e453c82de8afd;p=thirdparty%2Futil-linux.git cfdisk: fix mem leak and main_menu_action() logic [coverity scan] Signed-off-by: Karel Zak --- diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c index 6478389827..9455910f7c 100644 --- a/disk-utils/cfdisk.c +++ b/disk-utils/cfdisk.c @@ -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);