[PATCH] plug two more leaks in gpt_write

Jim Meyering meyering at redhat.com
Thu May 29 19:48:14 UTC 2008


* 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




More information about the parted-devel mailing list