[parted-devel] [PATCH] plug memory leak in gpt_read()

Petr Uzel petr.uzel at suse.cz
Sat Nov 8 14:31:15 UTC 2008


Hello everybody,

attached patch plugs a leak in gpt_read(). It may occur only in a very
special situation, i.e. if backup GPT is found not to be in the last
sector of the disk.


Signed-off-by: Petr Uzel <petr.uzel at suse.cz>
---
 libparted/labels/gpt.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 13d2e88..7bb8472 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -828,7 +828,6 @@ gpt_read (PedDisk * disk)
 				<= disk->dev->length - 1, goto error_free_gpt);
 		if ((PedSector) PED_LE64_TO_CPU (gpt->AlternateLBA)
 				< disk->dev->length - 1) {
-			char* zeros = ped_malloc (pth_get_size (disk->dev));
 
 #ifndef DISCOVER_ONLY
 			if (ped_exception_throw (
@@ -841,11 +840,13 @@ gpt_read (PedDisk * disk)
 					== PED_EXCEPTION_CANCEL)
 				goto error_free_gpt;
 
+			char* zeros = ped_malloc (pth_get_size (disk->dev));
 			write_back = 1;
 			memset (zeros, 0, disk->dev->sector_size);
 			ped_device_write (disk->dev, zeros,
 					  PED_LE64_TO_CPU (gpt->AlternateLBA),
 					  1);
+			free (zeros);
 #endif /* !DISCOVER_ONLY */
 		}
 	} else { /* primary GPT *not* ok */
-- 
1.6.0.2


-- 
Best regards / s pozdravem

Petr Uzel, Packages maintainer
---------------------------------------------------------------------
SUSE LINUX, s.r.o.                          e-mail: puzel at suse.cz
Lihovarská 1060/12                          tel: +420 284 028 964
190 00 Prague 9                             fax: +420 284 028 951
Czech Republic                              http://www.suse.cz



More information about the parted-devel mailing list