[PATCH] don't exhaust virtual memory for mklabel on a loopback device

Jim Meyering meyering at redhat.com
Wed Aug 6 17:31:16 UTC 2008


* libparted/arch/linux.c (_disk_sync_part_table): Handle the case in
which ped_disk_get_last_partition_num(disk) fails.
(_dm_reread_part_table): Likewise.
---
 libparted/arch/linux.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index df5a3ec..79ff509 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -2218,11 +2218,15 @@ _blkpg_remove_partition (PedDisk* disk, int n)
 static int
 _disk_sync_part_table (PedDisk* disk)
 {
-        int     i;
-        int     last = PED_MIN (ped_disk_get_last_partition_num (disk), 16);
+        int largest_partnum = ped_disk_get_last_partition_num (disk);
+        if (largest_partnum <= 0)
+          return 1;
+
+        int     last = PED_MIN (largest_partnum, 16);
         int*    rets = ped_malloc(sizeof(int) * last);
         int*    errnums = ped_malloc(sizeof(int) * last);
         int     ret = 1;
+        int     i;

         for (i = 1; i <= last; i++) {
                 rets[i - 1] = _blkpg_remove_partition (disk, i);
@@ -2439,8 +2443,12 @@ err:
 static int
 _dm_reread_part_table (PedDisk* disk)
 {
+        int largest_partnum = ped_disk_get_last_partition_num (disk);
+        if (largest_partnum <= 0)
+          return 1;
+
         int     rc = 1;
-        int     last = PED_MIN (ped_disk_get_last_partition_num (disk), 16);
+        int     last = PED_MIN (largest_partnum, 16);
         int     i;

         sync();
--
1.6.0.rc1.92.g189f7



More information about the parted-devel mailing list