summaryrefslogtreecommitdiff
path: root/parted
diff options
context:
space:
mode:
authorWang Dong <dongdwdw@linux.vnet.ibm.com>2016-12-23 06:53:37 +0100
committerBrian C. Lane <bcl@redhat.com>2017-05-01 15:03:31 -0700
commitaf150f6764a08eae4b4cf448c392259c067a1523 (patch)
tree53deace03a5c893828ab9d4fcc72e73d07027271 /parted
parent149f009c3b4ab6bac8059b48142a1c3f698c8e53 (diff)
downloadparted-af150f6764a08eae4b4cf448c392259c067a1523.tar.gz
parted: fix wrong error label jump in mkpart
When the user makes a new partition, if parted fails to add the partition to disk, it jumps to wrong error label. In this situation, this new partition actually is not a node in disk data structure. But in the wrong error label, it pretends this is a node and removes it as a list node, leading to other partition in this disk deleted. This might lead to a memory leak. Because if there are other partitions, it just removes them from list without releasing the resource. And this also leads to different disk information between memory and device. This is confusing. But when the new partition is added to disk successfully and if any operations followed fail, this partition should be removed from disk and destroyed. Signed-off-by: Wang Dong <dongdwdw@linux.vnet.ibm.com> Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
Diffstat (limited to 'parted')
-rw-r--r--parted/parted.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/parted/parted.c b/parted/parted.c
index a72a4eb..4bb7911 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -742,7 +742,7 @@ do_mkpart (PedDevice** dev, PedDisk** diskp)
ped_constraint_destroy (constraint_any);
if (!added_ok)
- goto error_remove_part;
+ goto error_destroy_simple_constraints;
if (!ped_geometry_test_sector_inside(range_start, part->geom.start) ||
!ped_geometry_test_sector_inside(range_end, part->geom.end)) {
@@ -817,12 +817,12 @@ do_mkpart (PedDevice** dev, PedDisk** diskp)
free (part_name); /* avoid double-free upon failure */
part_name = NULL;
if (!ped_partition_set_system (part, fs_type))
- goto error;
+ goto error_remove_part;
if (ped_partition_is_flag_available (part, PED_PARTITION_LBA))
ped_partition_set_flag (part, PED_PARTITION_LBA, 1);
if (!ped_disk_commit (disk))
- goto error;
+ goto error_remove_part;
/* clean up */
if (range_start != NULL)
@@ -845,7 +845,8 @@ error_remove_part:
error_destroy_simple_constraints:
ped_partition_destroy (part);
error:
- free (part_name);
+ if (part_name)
+ free (part_name);
if (range_start != NULL)
ped_geometry_destroy (range_start);
if (range_end != NULL)