[PATCH] ui: mkpart: avoid double free

Jim Meyering meyering at redhat.com
Sat Dec 12 17:31:04 UTC 2009


* parted/parted.c (do_mkpart): This function frees "part_name"
immediately after the final use, but also upon e.g., ped_disk_commit
failure.  Set part_name to NULL after the first free, to make
the second a no-op after the first.
---
 parted/parted.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/parted/parted.c b/parted/parted.c
index dba376d..6919701 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -878,7 +878,8 @@ do_mkpart (PedDevice** dev)
         /* set minor attributes */
         if (part_name)
                 PED_ASSERT (ped_partition_set_name (part, part_name), return 0);
-        free (part_name);
+        free (part_name);  /* avoid double-free upon failure */
+        part_name = NULL;
         if (!ped_partition_set_system (part, fs_type))
                 goto error_destroy_disk;
         if (ped_partition_is_flag_available (part, PED_PARTITION_LBA))
--
1.6.6.rc2.275.g51e2d



More information about the parted-devel mailing list