[PATCH] plug leaks in parted.c

Jim Meyering meyering at redhat.com
Thu May 29 17:36:02 UTC 2008


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




More information about the parted-devel mailing list