Re: [PATCH] Memory leak in scsi_debug found by checker

From: Felipe W Damasio
Date: Tue Sep 23 2003 - 14:15:26 EST


Forgot the patch :)

Felipe W Damasio wrote:
Hi James,

Patch against 2.6-test5.

If in the middle of loop a kmalloc failed, that means that the previous calls succeeded..so they must be also be freed (and removed from the dev_info_list).

Please review and consider applying.

Cheers,

Felipe

--- linux-2.6.0-test5/drivers/scsi/scsi_debug.c.orig 2003-09-23 15:46:57.000000000 -0300
+++ linux-2.6.0-test5/drivers/scsi/scsi_debug.c 2003-09-23 15:43:39.000000000 -0300
@@ -1614,7 +1614,7 @@
printk(KERN_ERR "%s: out of memory at line %d\n",
__FUNCTION__, __LINE__);
error = -ENOMEM;
- goto clean1;
+ goto clean;
}
memset(sdbg_devinfo, 0, sizeof(*sdbg_devinfo));
sdbg_devinfo->sdbg_host = sdbg_host;
@@ -1634,12 +1634,12 @@
error = device_register(&sdbg_host->dev);

if (error)
- goto clean2;
+ goto clean;

++scsi_debug_add_host;
return error;

-clean2:
+clean:
list_for_each_safe(lh, lh_sf, &sdbg_host->dev_info_list) {
sdbg_devinfo = list_entry(lh, struct sdebug_dev_info,
dev_list);
@@ -1647,7 +1647,6 @@
kfree(sdbg_devinfo);
}

-clean1:
kfree(sdbg_host);
return error;
}