From: Karel Zak Date: Thu, 29 Jan 2015 09:49:51 +0000 (+0100) Subject: libfdisk: make fdisk_partition_to_string() more robust [coverity scan] X-Git-Tag: v2.26-rc2~52 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=edc4cf94a86cda2f5476a7be98453ee027820913;p=thirdparty%2Futil-linux.git libfdisk: make fdisk_partition_to_string() more robust [coverity scan] Signed-off-by: Karel Zak --- diff --git a/libfdisk/src/partition.c b/libfdisk/src/partition.c index ba9f597a35..9a02993c30 100644 --- a/libfdisk/src/partition.c +++ b/libfdisk/src/partition.c @@ -661,7 +661,7 @@ int fdisk_partition_to_string(struct fdisk_partition *pa, int rc = 0; uint64_t x; - if (!pa || !cxt) + if (!pa || !cxt || !data) return -EINVAL; switch (id) { @@ -762,13 +762,16 @@ int fdisk_partition_to_string(struct fdisk_partition *pa, return -EINVAL; } - if (rc < 0) + if (rc < 0) { rc = -ENOMEM; - else if (rc > 0) + free(p); + p = NULL; + + } else if (rc > 0) rc = 0; - if (data) - *data = p; + *data = p; + return rc; }