[parted-devel] [Patch] memory leak in probe_filesystem_for_geom in dos.c

Mike Hommey mh at glandium.org
Thu Feb 22 22:39:09 CET 2007


Hi,

Since I can't attach the patch in Trac because of:
OSError: [Errno 13] Permission denied:
'/var/lib/gforge/chroot/home/groups/parted/srv/trac/attachments/ticket'

Here it is, attached.

The bug is http://parted.alioth.debian.org/cgi-bin/trac.cgi/ticket/16

Cheers,

Mike
-------------- next part --------------
--- dos.c.orig	2007-02-22 22:11:08.533075000 +0100
+++ dos.c	2007-02-22 22:13:03.160238750 +0100
@@ -421,6 +421,7 @@
 	unsigned char* buf;
 	int sectors;
 	int heads;
+	int res = 0;
 
 	PED_ASSERT (bios_geom        != NULL, return 0);
         PED_ASSERT (part             != NULL, return 0);
@@ -430,33 +431,39 @@
 
         buf = ped_malloc (part->disk->dev->sector_size);
         
-	if (!part->fs_type)
+	if (!buf)
 		return 0;
 
+	if (!part->fs_type)
+		goto end;
+
 	found = 0;
 	for (i = 0; ms_types[i]; i++) {
 		if (!strcmp(ms_types[i], part->fs_type->name))
 			found = 1;
 	}
 	if (!found)
-		return 0;
+		goto end;
 
 	if (!ped_geometry_read(&part->geom, buf, 0, 1))
-		return 0;
+		goto end;
 
 	/* shared by the start of all Microsoft file systems */
 	sectors = buf[0x18] + (buf[0x19] << 8);
 	heads = buf[0x1a] + (buf[0x1b] << 8);
 
 	if (sectors < 1 || sectors > 63)
-		return 0;
+		goto end;
 	if (heads > 255 || heads < 1)
-		return 0;
+		goto end;
 
 	bios_geom->sectors = sectors;
 	bios_geom->heads = heads;
 	bios_geom->cylinders = part->disk->dev->length / (sectors * heads);
-	return 1;
+	res = 1;
+end:
+	ped_free(buf);
+	return res;
 }
 
 /* This function attempts to infer the BIOS CHS geometry of the hard disk


More information about the parted-devel mailing list