[parted-devel] [PATCH] gpt.c: plug a memory leak in gpt_read()

Petr Uzel petr.uzel at suse.cz
Thu Mar 5 15:52:20 UTC 2009


Hi,

thanks to Joel for the reminder. I've modified the patch to apply to
current head. I've also tried to follow your rules for the changelog,
so I hope it is OK now.

Thanks,


=======


* libparted/labels/gpt.c (gpt_read): free local variable, "zeros"
---
 libparted/labels/gpt.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index be8f264..25d0680 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -812,6 +812,7 @@ gpt_read (PedDisk * disk)
 	int i;
 #ifndef DISCOVER_ONLY
 	int write_back = 0;
+	char *zeros;
 #endif
 
 	ped_disk_delete_all (disk);
@@ -833,7 +834,6 @@ gpt_read (PedDisk * disk)
 
 		if ((PedSector) PED_LE64_TO_CPU (gpt->AlternateLBA)
 				< disk->dev->length - 1) {
-			char* zeros = ped_malloc (pth_get_size (disk->dev));
 
 #ifndef DISCOVER_ONLY
 			switch (ped_exception_throw (
@@ -846,11 +846,13 @@ gpt_read (PedDisk * disk)
 				case PED_EXCEPTION_CANCEL:
 					goto error_free_gpt;
 				case PED_EXCEPTION_FIX:
+					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);
 					break;
 				default:
 					break;
-- 
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