bug-parted
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

memory leak in gpt.c


From: Harley D. Eades III
Subject: memory leak in gpt.c
Date: Fri, 23 Dec 2005 00:12:05 -0600

Hello everyone,

Here is a patch that fixes a memory leak in libparted/labels/gpt.c
If no one objects I can commit this.

Before:
==16525== 517 (97 direct, 420 indirect) bytes in 1 blocks are definitely
lost in loss record 11 of 17
==16525==    at 0x1B9008A2: malloc (vg_replace_malloc.c:149)
==16525==    by 0x1B910257: ped_malloc (libparted.c:278)
==16525==    by 0x1B957204: pth_new (gpt.c:248)
==16525==    by 0x1B9572F4: pth_new_from_raw (gpt.c:271)
==16525==    by 0x1B9575E2: gpt_probe (gpt.c:384)
==16525==    by 0x1B911D84: ped_disk_probe (disk.c:147)
==16525==    by 0x1B911E38: ped_disk_new (disk.c:178)
==16525==    by 0x8059562: fdisk (fdisk.c:2088)
==16525==    by 0x804F7B0: main (parted.c:1926)
==16525==
==16525== LEAK SUMMARY:
==16525==    definitely lost: 97 bytes in 1 blocks.
==16525==    indirectly lost: 420 bytes in 1 blocks.
==16525==      possibly lost: 0 bytes in 0 blocks.
==16525==    still reachable: 56062 bytes in 198 blocks.
==16525==         suppressed: 14 bytes in 1 blocks.
==16525== Reachable blocks (those to which a pointer was found) are not
shown.
==16525== To see them, rerun with: --show-reachable=yes

After:
==18095== LEAK SUMMARY:
==18095==    definitely lost: 0 bytes in 0 blocks.
==18095==      possibly lost: 0 bytes in 0 blocks.
==18095==    still reachable: 56062 bytes in 198 blocks.
==18095==         suppressed: 14 bytes in 1 blocks.
==18095== Reachable blocks (those to which a pointer was found) are not
shown.
==18095== To see them, rerun with: --show-reachable=yes


Cheers
-- 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------

2005-12-23  Harley D. Eades III  <address@hidden>
* libparted/labels/gpt.c (gpt_probe): Moved the call to 
pth_new_from_raw () into the same scope as gpt, added two new calls to
ped_free() for the gpt structure, and combined the two ped_device_reads
into one if, because both if-statement bodies were equal.

--- libparted/labels/gpt.c      2005-12-20 11:18:03.000000000 -0600
+++ ../people/hde/trunk+fdisk/libparted/labels/gpt.c    2005-12-22
23:51:34.000000000 -0600
@@ -380,24 +380,21 @@
static int
gpt_probe (const PedDevice * dev)
{
-       GuidPartitionTableHeader_t* gpt;
         uint8_t* pth_raw = ped_malloc (pth_get_size (dev));
+       GuidPartitionTableHeader_t* gpt = pth_new_from_raw (dev,
pth_raw);
        LegacyMBR_t legacy_mbr;
        int gpt_sig_found = 0;

        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)) {
                if (gpt->Signature ==
PED_CPU_TO_LE64(GPT_HEADER_SIGNATURE))
                        gpt_sig_found = 1;
        }
-
+
+       ped_free (gpt->Reserved2);
+       ped_free (gpt);
         ped_free (pth_raw);

        if (!gpt_sig_found)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]