[PATCH 2/5] gpt: do not leak a GPT header on an error path
Jim Meyering
meyering at redhat.com
Fri Jan 15 18:34:00 UTC 2010
* libparted/labels/gpt.c (gpt_write): Avoid a leak by freeing the
header buffer after pth_get_raw call where it's used, but before
checking whether that pth_get_raw call succeeded.
Avoid another leak in identical just 10 lines down.
Add "FIXME: caution..." comments to warn about the duplication.
---
libparted/labels/gpt.c | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index fe1f300..76537fd 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -1208,11 +1208,13 @@ gpt_write (const PedDisk *disk)
goto error_free_ptes;
/* Write PTH and PTEs */
+ /* FIXME: Caution: this code is nearly identical to what's just below. */
if (_generate_header (disk, 0, ptes_crc, &gpt) != 0)
goto error_free_ptes;
- if ((pth_raw = pth_get_raw (disk->dev, gpt)) == NULL)
- goto error_free_ptes;
+ pth_raw = pth_get_raw (disk->dev, gpt);
pth_free (gpt);
+ if (pth_raw == NULL)
+ goto error_free_ptes;
int write_ok = ped_device_write (disk->dev, pth_raw, 1, 1);
free (pth_raw);
if (!write_ok)
@@ -1222,11 +1224,13 @@ gpt_write (const PedDisk *disk)
goto error_free_ptes;
/* Write Alternate PTH & PTEs */
+ /* FIXME: Caution: this code is nearly identical to what's just above. */
if (_generate_header (disk, 1, ptes_crc, &gpt) != 0)
goto error_free_ptes;
- if ((pth_raw = pth_get_raw (disk->dev, gpt)) == NULL)
- goto error_free_ptes;
+ pth_raw = pth_get_raw (disk->dev, gpt);
pth_free (gpt);
+ if (pth_raw == NULL)
+ goto error_free_ptes;
write_ok = ped_device_write (disk->dev, pth_raw, disk->dev->length - 1, 1);
free (pth_raw);
if (!write_ok)
--
1.6.6.556.gd6679
More information about the parted-devel
mailing list