[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: memory leak in gpt.c (Fixed the correct way)
From: |
Harley D. Eades III |
Subject: |
Re: memory leak in gpt.c (Fixed the correct way) |
Date: |
Sun, 25 Dec 2005 23:41:48 -0600 |
On Fri, 2005-12-23 at 16:40 -0600, Harley D. Eades III wrote:
> On Fri, 2005-12-23 at 23:19 +0100, Patrick Leslie Polzer wrote:
> > On Fri, 23 Dec 2005 00:21:08 -0600
> > Harley D. Eades III <"Harley D. Eades III" <address@hidden>> wrote:
> >
> > | +
> > | + ped_free (gpt->Reserved2);
> > | + ped_free (gpt);
> > | ped_free (pth_raw);
> > I think this justifies a pth_free() function.
Done, here she is. :) These are the only places I could see right off
that needed to use pth_free(), if anyone knows any other spots please
add them, we need to make sure we don't have memory leaks in libparted.
Ok to commit?
2005-12-25 Harley D. Eades III <address@hidden>
* libparted/labels/gpt.c (pth_free): New function.
* libparted/labels/gpt.c (gpt_probe): Added a call to pth_free().
* libparted/labels/gpt.c (gpt_clobber): Now calls pth_free() on gpt
before returning and calls pth_free() on error_free_with_gpt instead
of ped_free().
--- libparted/labels/gpt.c 2005-12-25 22:52:06.000000000 -0600
+++ ../people/hde/trunk+fdisk/libparted/labels/gpt.c 2005-12-25
22:50:37.000000000 -0600
@@ -279,6 +279,14 @@
return pth;
}
+static void
+pth_free (GuidPartitionTableHeader_t* pth) {
+ if (pth->Reserved2)
+ ped_free (pth->Reserved2);
+
+ if (pth)
+ ped_free (pth);
+}
static uint8_t*
pth_get_raw (const PedDevice* dev, const GuidPartitionTableHeader_t*
pth)
@@ -387,17 +395,14 @@
PED_ASSERT (dev != NULL, return 0);
- if (ped_device_read(dev, pth_raw, 1, GPT_HEADER_SECTORS)) {
- gpt = pth_new_from_raw (dev, pth_raw);
- if (gpt->Signature ==
PED_CPU_TO_LE64(GPT_HEADER_SIGNATURE))
- gpt_sig_found = 1;
- }
- if (ped_device_read(dev, pth_raw, dev->length - 1,
GPT_HEADER_SECTORS)) {
- gpt = pth_new_from_raw (dev, pth_raw);
+ if (ped_device_read(dev, pth_raw, 1, GPT_HEADER_SECTORS)
+ || ped_device_read(dev, pth_raw, dev->length - 1,
GPT_HEADER_SECTORS)) {
+ gpt = pth_new_from_raw (dev, pth_raw);
if (gpt->Signature ==
PED_CPU_TO_LE64(GPT_HEADER_SIGNATURE))
gpt_sig_found = 1;
}
-
+
+ pth_free (gpt);
ped_free (pth_raw);
if (!gpt_sig_found)
@@ -468,10 +473,12 @@
return 0;
}
+ pth_free (gpt);
+
return 1;
error_free_with_gpt:
- ped_free (gpt);
+ pth_free (gpt);
error_free:
ped_free (pth_raw);
ped_free (zeroed_pth_raw);
@@ -796,6 +803,7 @@
ped_constraint_destroy (constraint_exact);
}
ped_free (ptes);
+
#ifndef DISCOVER_ONLY
if (write_back)
ped_disk_commit_to_dev (disk);
-- Harley
-----BEGIN GEEK CODE BLOCK-----
G: GCS-- d- a? C++++ B- E+++ W+++ N++ w--- X+++ b++ G e* r x+ z+++++
------END GEEK CODE BLOCK------
- memory leak in gpt.c (Fixed the correct way), Harley D. Eades III, 2005/12/23
- Re: memory leak in gpt.c (Fixed the correct way), Patrick Leslie Polzer, 2005/12/23
- Re: memory leak in gpt.c (Fixed the correct way), Harley D. Eades III, 2005/12/23
- Re: memory leak in gpt.c (Fixed the correct way),
Harley D. Eades III <=
- Re: memory leak in gpt.c (Fixed the correct way), Patrick Leslie Polzer, 2005/12/26
- Re: memory leak in gpt.c (Fixed the correct way), Håkon Løvdal, 2005/12/26
- Re: memory leak in gpt.c (Fixed the correct way), Patrick Leslie Polzer, 2005/12/26
- Re: memory leak in gpt.c (Fixed the correct way), Harley D. Eades III, 2005/12/26
- Re: memory leak in gpt.c (Fixed the correct way), Patrick Leslie Polzer, 2005/12/26
- Re: memory leak in gpt.c (Fixed the correct way), Harley D. Eades III, 2005/12/26
- Re: memory leak in gpt.c (Fixed the correct way), Otavio Salvador, 2005/12/26
- Re: memory leak in gpt.c (Fixed the correct way), Harley D. Eades III, 2005/12/26