Skip to contentSkip to conversation

do_mounts memory leak

PATCH New Randy.Dunlap 1 participant 1 message Feb 5, 2003 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 do_mounts memory leak

Hi,

The Stanford Checker identified a memory leak in init/do_mounts.c. This patch to 2.5.59 corrects it. Please apply.

Thanks,
~Randy

init/do_mounts.c renamed from init/do_mounts.c%LEAK +6 -6
diff -Naur ./init/do_mounts.c%LEAK ./init/do_mounts.c
@@ -653,12 +653,6 @@
 	/*
 	 * OK, time to copy in the data
 	 */
-	buf = kmalloc(BLOCK_SIZE, GFP_KERNEL);
-	if (buf == 0) {
-		printk(KERN_ERR "RAMDISK: could not allocate buffer\n");
-		goto done;
-	}
-
 	if (sys_ioctl(in_fd, BLKGETSIZE, (unsigned long)&devblocks) < 0)
 		devblocks = 0;
 	else
@@ -669,6 +663,12 @@
 
 	if (devblocks == 0) {
 		printk(KERN_ERR "RAMDISK: could not determine device size\n");
+		goto done;
+	}
+
+	buf = kmalloc(BLOCK_SIZE, GFP_KERNEL);
+	if (buf == 0) {
+		printk(KERN_ERR "RAMDISK: could not allocate buffer\n");
 		goto done;
 	}