These 9 change-sets plug many leaks and fix one
write-uninitialized error.  There are still leaks and
"ERRORS" reported by running the tests under valgrind,
but most of those involve ext2, which is lower priority, for now.
[create partition tables and partitions, not *file systems* with parted]

"make distcheck" still passes.
I'll push tomorrow.


>From 9f1c01c1f2931ffd0cff29ee0646f9db1c8978ba Mon Sep 17 00:00:00 2001
From: Jim Meyering <[EMAIL PROTECTED]>
Date: Thu, 29 May 2008 15:47:21 +0200
Subject: [PATCH] plug a leak in ped_device_get_constraint

* libparted/device.c (ped_device_get_constraint):
512 (224 direct, 288 indirect) bytes in 6 blocks are definitely lost...
  malloc (vg_replace_malloc.c:207)
  ped_malloc (libparted.c:270)
  ped_alignment_new (natmath.c:153)
  ped_device_get_constraint (device.c:432)
  do_mkpartfs (parted.c:927)
  command_run (command.c:139)
  non_interactive_mode (ui.c:1540)
  main (parted.c:2497)
---
 libparted/device.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/libparted/device.c b/libparted/device.c
index ac2a5cd..6595572 100644
--- a/libparted/device.c
+++ b/libparted/device.c
@@ -1,6 +1,6 @@
 /*
     libparted - a library for manipulating disk partitions
-    Copyright (C) 1999 - 2001, 2005, 2007 Free Software Foundation, Inc.
+    Copyright (C) 1999 - 2001, 2005, 2007-2008 Free Software Foundation, Inc.

     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -437,6 +437,7 @@ ped_device_get_constraint (PedDevice* dev)
                                 ped_geometry_new (dev, 0, dev->length),
                                 1, dev->length);

+        free (start_align);
         return c;
 }

-- 
1.5.6.rc0.30.g7c3f3


>From ffaf0b817515db29b27269b5b906c79bb6a72d7c Mon Sep 17 00:00:00 2001
From: Jim Meyering <[EMAIL PROTECTED]>
Date: Thu, 29 May 2008 19:36:02 +0200
Subject: [PATCH] plug leaks in parted.c

432 (144 direct, 288 indirect) bytes in 3 blocks are definitely lost...
   at 0x4A0739E: malloc (vg_replace_malloc.c:207)
   by 0x416EF3: ped_malloc (libparted.c:270)
   by 0x41D9D2: ped_constraint_new (constraint.c:100)
   by 0x4151A4: ped_device_get_constraint (device.c:439)
   by 0x40B928: do_mkpartfs (parted.c:927)
   by 0x40A055: command_run (command.c:139)
   by 0x41217C: non_interactive_mode (ui.c:1540)
   by 0x40EEB1: main (parted.c:2497)

And another:

* parted/parted.c (do_mkpartfs): Here's one of the signatures:
288 (96 direct, 192 indirect) bytes in 2 blocks are definitely lost...
   at 0x4A0739E: malloc (vg_replace_malloc.c:207)
   by 0x416EF3: ped_malloc (libparted.c:270)
   by 0x41D9D2: ped_constraint_new (constraint.c:100)
   by 0x41DE2C: ped_constraint_intersect (constraint.c:232)
   by 0x40B971: do_mkpartfs (parted.c:930)
   by 0x40A055: command_run (command.c:139)
   by 0x41217C: non_interactive_mode (ui.c:1540)
   by 0x40EEB1: main (parted.c:2497)

* parted/parted.c (do_mkpart): Likewise for this function,
since do_mkpart is nearly identical to do_mkpartfs.
---
 parted/parted.c |   26 +++++++++++---------------
 1 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/parted/parted.c b/parted/parted.c
index 4e16f92..4f04332 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -17,6 +17,7 @@
 */

 #include <config.h>
+#include <stdbool.h>

 #include "closeout.h"
 #include "configmake.h"
@@ -757,12 +758,16 @@ do_mkpart (PedDevice** dev)

         final_constraint = ped_constraint_intersect (user_constraint,
                         dev_constraint);
+        ped_constraint_destroy (user_constraint);
+        ped_constraint_destroy (dev_constraint);
         if (!final_constraint)
                 goto error_destroy_simple_constraints;

         /* subject to partition constraint */
         ped_exception_fetch_all();
-        if (!ped_disk_add_partition (disk, part, final_constraint)) {
+        bool added_ok = ped_disk_add_partition (disk, part, final_constraint);
+        ped_constraint_destroy (final_constraint);
+        if (!added_ok) {
                 ped_exception_leave_all();
                
                 if (ped_disk_add_partition (disk, part,
@@ -810,10 +815,6 @@ do_mkpart (PedDevice** dev)
                 goto error_destroy_disk;
         
         /* clean up */
-        ped_constraint_destroy (final_constraint);
-        ped_constraint_destroy (user_constraint);
-        ped_constraint_destroy (dev_constraint);
-
         ped_disk_destroy (disk);
         
         if (range_start != NULL)
@@ -833,10 +834,7 @@ do_mkpart (PedDevice** dev)

 error_remove_part:
         ped_disk_remove_partition (disk, part);
-        ped_constraint_destroy (final_constraint);
 error_destroy_simple_constraints:
-        ped_constraint_destroy (user_constraint);
-        ped_constraint_destroy (dev_constraint);
         ped_partition_destroy (part);
 error_destroy_disk:
         ped_disk_destroy (disk);
@@ -920,12 +918,16 @@ do_mkpartfs (PedDevice** dev)

         final_constraint = ped_constraint_intersect (user_constraint,
                                                      dev_constraint);
+        ped_constraint_destroy (user_constraint);
+        ped_constraint_destroy (dev_constraint);
         if (!final_constraint)
                 goto error_destroy_simple_constraints;

         /* subject to partition constraint */
         ped_exception_fetch_all();
-        if (!ped_disk_add_partition (disk, part, final_constraint)) {
+       bool added_ok = ped_disk_add_partition (disk, part, final_constraint);
+        ped_constraint_destroy (final_constraint);
+        if (!added_ok) {
                 ped_exception_leave_all();
                
                 if (ped_disk_add_partition (disk, part,
@@ -977,9 +979,6 @@ do_mkpartfs (PedDevice** dev)
                 goto error_destroy_disk;

         /* clean up */
-        ped_constraint_destroy (final_constraint);
-        ped_constraint_destroy (user_constraint);
-        ped_constraint_destroy (dev_constraint);

         ped_disk_destroy (disk);

@@ -1000,10 +999,7 @@ do_mkpartfs (PedDevice** dev)

 error_remove_part:
         ped_disk_remove_partition (disk, part);
-        ped_constraint_destroy (final_constraint);
 error_destroy_simple_constraints:
-        ped_constraint_destroy (user_constraint);
-        ped_constraint_destroy (dev_constraint);
         ped_partition_destroy (part);
 error_destroy_disk:
         ped_disk_destroy (disk);
-- 
1.5.6.rc0.30.g7c3f3


>From 9edcca96a2b53d8fd4da32d881888d7bcb95a043 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[EMAIL PROTECTED]>
Date: Thu, 29 May 2008 19:38:09 +0200
Subject: [PATCH] plug leak in ped_device_get_constraint

496 (208 direct, 288 indirect) bytes in 5 blocks are definitely lost...
   at 0x4A0739E: malloc (vg_replace_malloc.c:207)
   by 0x416EDF: ped_malloc (libparted.c:270)
   by 0x41CB40: ped_geometry_new (geom.c:79)
   by 0x415167: ped_device_get_constraint (device.c:438)
   by 0x40B928: do_mkpartfs (parted.c:927)
   by 0x40A055: command_run (command.c:139)
   by 0x41217C: non_interactive_mode (ui.c:1540)
   by 0x40EEB1: main (parted.c:2497)
---
 libparted/device.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/libparted/device.c b/libparted/device.c
index 6595572..b951dd2 100644
--- a/libparted/device.c
+++ b/libparted/device.c
@@ -431,12 +431,15 @@ ped_device_get_constraint (PedDevice* dev)

         PedAlignment* start_align = ped_alignment_new (multiplier, multiplier);
         
+        PedGeometry *s, *e;
         PedConstraint* c = ped_constraint_new (
                                 start_align, ped_alignment_any,
-                                ped_geometry_new (dev, 0, dev->length),
-                                ped_geometry_new (dev, 0, dev->length),
+                                s = ped_geometry_new (dev, 0, dev->length),
+                                e = ped_geometry_new (dev, 0, dev->length),
                                 1, dev->length);

+        free (s);
+        free (e);
         free (start_align);
         return c;
 }
-- 
1.5.6.rc0.30.g7c3f3


>From d7ae34826e319be81773273dccedc6b942e6c37a Mon Sep 17 00:00:00 2001
From: Jim Meyering <[EMAIL PROTECTED]>
Date: Thu, 29 May 2008 20:38:13 +0200
Subject: [PATCH] plug a leak in gpt_read

* libparted/labels/gpt.c (gpt_read):
7,195 bytes in 13 blocks are definitely lost...
   at 0x4A0739E: malloc (vg_replace_malloc.c:207)
   by 0x416F1B: ped_malloc (libparted.c:270)
   by 0x43E759: pth_new (gpt.c:287)
   by 0x43E83C: pth_new_from_raw (gpt.c:310)
   by 0x43F329: _read_header (gpt.c:627)
   by 0x43FB31: gpt_read (gpt.c:826)
   by 0x41882B: ped_disk_new (disk.c:210)
   by 0x40B773: do_mkpartfs (parted.c:884)
   by 0x40A055: command_run (command.c:139)
---
 libparted/labels/gpt.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 8bb9554..5be0235 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -924,6 +924,7 @@ gpt_read (PedDisk * disk)
                ped_disk_commit_to_dev (disk);
 #endif

+        pth_free (gpt);
        return 1;

 error_delete_all:
-- 
1.5.6.rc0.30.g7c3f3


>From 5120ff6829690ef9c4ae65b8d981c36965443a82 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[EMAIL PROTECTED]>
Date: Thu, 29 May 2008 20:47:44 +0200
Subject: [PATCH] plug leaks in gpt_write

* libparted/labels/gpt.c (gpt_write):
6,674 bytes in 11 blocks are definitely lost...
  at 0x4A0739E: malloc (vg_replace_malloc.c:207)
  by 0x416F1B: ped_malloc (libparted.c:270)
  by 0x43E76D: pth_new (gpt.c:289)
  by 0x43E7E2: pth_new_zeroed (gpt.c:298)
  by 0x43FF61: _generate_header (gpt.c:970)
  by 0x440434: gpt_write (gpt.c:1074)
  by 0x418F9A: ped_disk_commit_to_dev (disk.c:486)
  by 0x418FE0: ped_disk_commit (disk.c:509)
  by 0x40BB35: do_mkpartfs (parted.c:990)
---
 libparted/labels/gpt.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 5be0235..0d8357b 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -1065,6 +1065,7 @@ gpt_write(const PedDisk * disk)
        /* Write PTH and PTEs */
        _generate_header (disk, 0, ptes_crc, &gpt);
         pth_raw = pth_get_raw (disk->dev, gpt);
+        pth_free (gpt);
        if (!ped_device_write (disk->dev, pth_raw, 1, 1))
                goto error_free_ptes;
        if (!ped_device_write (disk->dev, ptes, 2, ptes_size / 
disk->dev->sector_size))
@@ -1073,6 +1074,7 @@ gpt_write(const PedDisk * disk)
        /* Write Alternate PTH & PTEs */
        _generate_header (disk, 1, ptes_crc, &gpt);
         pth_raw = pth_get_raw (disk->dev, gpt);
+        pth_free (gpt);
        if (!ped_device_write (disk->dev, pth_raw, disk->dev->length - 1, 1))
                goto error_free_ptes;
        if (!ped_device_write (disk->dev, ptes,
-- 
1.5.6.rc0.30.g7c3f3


>From dcf3de7a09e604bc35ee61fc023372c415dda703 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[EMAIL PROTECTED]>
Date: Thu, 29 May 2008 20:53:08 +0200
Subject: [PATCH] plug a blatant leak in gpt_write

* libparted/labels/gpt.c (gpt_write):
1,536 bytes in 3 blocks are definitely lost in loss record 9 of 11
   at 0x4A0739E: malloc (vg_replace_malloc.c:207)
   by 0x416F1B: ped_malloc (libparted.c:270)
   by 0x44021F: gpt_write (gpt.c:1036)
   by 0x418F9A: ped_disk_commit_to_dev (disk.c:486)
   by 0x418FE0: ped_disk_commit (disk.c:509)
   by 0x40AF7A: do_mklabel (parted.c:622)
   by 0x40A055: command_run (command.c:139)
   by 0x4121A4: non_interactive_mode (ui.c:1540)
   by 0x40EED8: main (parted.c:2499)
---
 libparted/labels/gpt.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 0d8357b..148eea3 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -1033,7 +1033,7 @@ gpt_write(const PedDisk * disk)
        GPTDiskData* gpt_disk_data;
        GuidPartitionEntry_t* ptes;
        uint32_t ptes_crc;
-        uint8_t* pth_raw = ped_malloc (pth_get_size (disk->dev));
+        uint8_t* pth_raw;
        GuidPartitionTableHeader_t* gpt;
        PedPartition* part;
        int ptes_size;
-- 
1.5.6.rc0.30.g7c3f3


>From bf31830507596c24975695d7d303f11de548e41c Mon Sep 17 00:00:00 2001
From: Jim Meyering <[EMAIL PROTECTED]>
Date: Thu, 29 May 2008 21:48:14 +0200
Subject: [PATCH] plug two more leaks in gpt_write

* libparted/labels/gpt.c (gpt_write):
1,024 bytes in 2 blocks are definitely lost...
   at 0x4A0739E: malloc (vg_replace_malloc.c:207)
   by 0x416F1B: ped_malloc (libparted.c:270)
   by 0x43E967: pth_get_raw (gpt.c:334)
   by 0x44039D: gpt_write (gpt.c:1067)
   by 0x418F9A: ped_disk_commit_to_dev (disk.c:486)
   by 0x418FE0: ped_disk_commit (disk.c:509)
   by 0x40AF7A: do_mklabel (parted.c:622)
   by 0x40A055: command_run (command.c:139)
   by 0x4121A4: non_interactive_mode (ui.c:1540)
---
 libparted/labels/gpt.c |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 148eea3..d09d751 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -38,6 +38,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <uuid/uuid.h>
+#include <stdbool.h>

 #if ENABLE_NLS
 #  include <libintl.h>
@@ -1064,18 +1065,24 @@ gpt_write(const PedDisk * disk)

        /* Write PTH and PTEs */
        _generate_header (disk, 0, ptes_crc, &gpt);
-        pth_raw = pth_get_raw (disk->dev, gpt);
-        pth_free (gpt);
-       if (!ped_device_write (disk->dev, pth_raw, 1, 1))
+       pth_raw = pth_get_raw (disk->dev, gpt);
+       pth_free (gpt);
+       bool write_ok = ped_device_write (disk->dev, pth_raw, 1, 1);
+       free (pth_raw);
+       if (!write_ok)
                goto error_free_ptes;
-       if (!ped_device_write (disk->dev, ptes, 2, ptes_size / 
disk->dev->sector_size))
+       if (!ped_device_write (disk->dev, ptes, 2,
+                              ptes_size / disk->dev->sector_size))
                goto error_free_ptes;

        /* Write Alternate PTH & PTEs */
        _generate_header (disk, 1, ptes_crc, &gpt);
         pth_raw = pth_get_raw (disk->dev, gpt);
         pth_free (gpt);
-       if (!ped_device_write (disk->dev, pth_raw, disk->dev->length - 1, 1))
+       write_ok = ped_device_write (disk->dev, pth_raw,
+                                    disk->dev->length - 1, 1);
+       free (pth_raw);
+       if (!write_ok)
                goto error_free_ptes;
        if (!ped_device_write (disk->dev, ptes,
                               disk->dev->length - 1 - ptes_size / 
disk->dev->sector_size,
-- 
1.5.6.rc0.30.g7c3f3


>From 7b7ef19faed87818b734ad1247af8ed35bf09909 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[EMAIL PROTECTED]>
Date: Thu, 29 May 2008 22:35:06 +0200
Subject: [PATCH] plug leaks in do_print

* parted/parted.c (do_print):
25 bytes in 8 blocks are definitely lost...
   at 0x4A0739E: malloc (vg_replace_malloc.c:207)
   by 0x416E67: ped_malloc (libparted.c:234)
   by 0x41751F: ped_strdup (unit.c:179)
   by 0x417778: ped_unit_format_custom_byte (unit.c:220)
   by 0x417A90: ped_unit_format (unit.c:297)
   by 0x40CD85: do_print (parted.c:1517)
   by 0x40A035: command_run (command.c:139)
   by 0x41210C: non_interactive_mode (ui.c:1540)
   by 0x40EE41: main (parted.c:2482)

10 bytes in 4 blocks are definitely lost...
   at 0x4A0739E: malloc (vg_replace_malloc.c:207)
   by 0x416E9B: ped_malloc (libparted.c:234)
   by 0x417553: ped_strdup (unit.c:179)
   by 0x4177AC: ped_unit_format_custom_byte (unit.c:220)
   by 0x417AC4: ped_unit_format (unit.c:297)
   by 0x40CE34: do_print (parted.c:1527)
   by 0x40A035: command_run (command.c:139)
   by 0x412140: non_interactive_mode (ui.c:1540)
   by 0x40EE75: main (parted.c:2485)
---
 parted/parted.c |   23 ++++++++++++++---------
 1 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/parted/parted.c b/parted/parted.c
index 4f04332..4af72ac 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -1508,15 +1508,20 @@ do_print (PedDevice** dev)
                 else
                     fputs ("1:", stdout);

-                printf ("%s:", ped_unit_format (*dev, part->geom.start));
-                printf ("%s:", ped_unit_format_byte (
-                                *dev,
-                                (part->geom.end + 1) * 
-                                (*dev)->sector_size - 1));
-
-                if (ped_unit_get_default() != PED_UNIT_CHS)
-                    printf ("%s:", ped_unit_format (*dev,
-                                                    part->geom.length));
+                char *s = ped_unit_format (*dev, part->geom.start);
+                printf ("%s:", s);
+                free (s);
+                s = ped_unit_format_byte (*dev,
+                                          (part->geom.end + 1) *
+                                          (*dev)->sector_size - 1);
+                printf ("%s:", s);
+                free (s);
+
+                if (ped_unit_get_default() != PED_UNIT_CHS) {
+                    s = ped_unit_format (*dev, part->geom.length);
+                    printf ("%s:", s);
+                    free (s);
+                }
                     
                 if (!(part->type & PED_PARTITION_FREESPACE)) {

-- 
1.5.6.rc0.30.g7c3f3


>From 47eccc1533631cc1efdfaf915fc1ea6de9bb490f Mon Sep 17 00:00:00 2001
From: Jim Meyering <[EMAIL PROTECTED]>
Date: Fri, 30 May 2008 21:10:06 +0200
Subject: [PATCH] gpt_write: fix a write-uninitialized error

* libparted/labels/gpt.c (gpt_partition_new):
  ==32570== Syscall param write(buf) points to uninitialised byte(s)
  ==32570==    at 0x36CF8D6540: __write_nocancel (in /lib64/libc-2.8.so)
  ==32570==    by 0x443D29: linux_write (linux.c:1642)
  ==32570==    by 0x414E4E: ped_device_write (device.c:370)
  ==32570==    by 0x4404CE: gpt_write (gpt.c:1091)
  ==32570==    by 0x418F16: ped_disk_commit_to_dev (disk.c:486)
  ==32570==    by 0x418F5C: ped_disk_commit (disk.c:509)
  ==32570==    by 0x40BAD6: do_mkpartfs (parted.c:981)
  ==32570==    by 0x40A035: command_run (command.c:139)
  ==32570==    by 0x412150: non_interactive_mode (ui.c:1540)
  ==32570==    by 0x40EE83: main (parted.c:2487)
  ==32570==  Address 0x501b63a is 58 bytes inside a block of size 16,384 alloc'd
  ==32570==    at 0x4A04FC0: memalign (vg_replace_malloc.c:460)
  ==32570==    by 0x4A0507A: posix_memalign (vg_replace_malloc.c:569)
  ==32570==    by 0x443CED: linux_write (linux.c:1637)
  ==32570==    by 0x414E4E: ped_device_write (device.c:370)
  ==32570==    by 0x4404CE: gpt_write (gpt.c:1091)
  ==32570==    by 0x418F16: ped_disk_commit_to_dev (disk.c:486)
  ==32570==    by 0x418F5C: ped_disk_commit (disk.c:509)
  ==32570==    by 0x40BAD6: do_mkpartfs (parted.c:981)
  ==32570==    by 0x40A035: command_run (command.c:139)
  ==32570==    by 0x412150: non_interactive_mode (ui.c:1540)
  ==32570==    by 0x40EE83: main (parted.c:2487)

  reproduce with this:
  dev=f
  dd if=/dev/null of=$dev bs=1 seek=30M 2>/dev/null
  ./parted -s $dev mklabel gpt
  valgrind ./parted -s $dev mkpartfs primary ext2 0 16795000B
---
 libparted/labels/gpt.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index d09d751..1e0becd 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -1154,7 +1154,7 @@ gpt_partition_new (const PedDisk* disk,
         gpt_part_data->msftres = 0;
        uuid_generate ((unsigned char*) &gpt_part_data->uuid);
        swap_uuid_and_efi_guid((unsigned char*)(&gpt_part_data->uuid));
-       strcpy (gpt_part_data->name, "");
+       memset (gpt_part_data->name, 0, sizeof gpt_part_data->name);
        return part;

 error_free_part:
-- 
1.5.6.rc0.30.g7c3f3


_______________________________________________
parted-devel mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/parted-devel

Reply via email to