[PATCH 4/5] dos: don't leak a constraint upon partition-add failure

Jim Meyering meyering at redhat.com
Fri Jan 15 19:14:38 UTC 2010


* libparted/labels/dos.c (read_table): Free constraint upon failure.
---
 libparted/labels/dos.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c
index 6b8d6cb..339acf4 100644
--- a/libparted/labels/dos.c
+++ b/libparted/labels/dos.c
@@ -873,7 +873,6 @@ read_table (PedDisk* disk, PedSector sector, int is_extended_table)
 	PedPartition*		part;
 	PedPartitionType	type;
 	PedSector		lba_offset;
-	PedConstraint*		constraint_exact;

 	PED_ASSERT (disk != NULL, return 0);
 	PED_ASSERT (disk->dev != NULL, return 0);
@@ -944,10 +943,12 @@ read_table (PedDisk* disk, PedSector sector, int is_extended_table)
 		if (type != PED_PARTITION_EXTENDED)
 			part->fs_type = ped_file_system_probe (&part->geom);

-		constraint_exact = ped_constraint_exact (&part->geom);
-		if (!ped_disk_add_partition (disk, part, constraint_exact))
-			goto error;
+		PedConstraint *constraint_exact
+		  = ped_constraint_exact (&part->geom);
+		bool ok = ped_disk_add_partition (disk, part, constraint_exact);
 		ped_constraint_destroy (constraint_exact);
+		if (!ok)
+			goto error;

 		/* non-nested extended partition */
 		if (part->type == PED_PARTITION_EXTENDED) {
--
1.6.6.556.gd6679




More information about the parted-devel mailing list