Commit c16e5061 authored by Felipe Damasio's avatar Felipe Damasio Committed by James Bottomley

[PATCH] Memory leak in scsi_debug found by checker

    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).
parent 9865adc3
...@@ -1614,7 +1614,7 @@ static int sdebug_add_adapter() ...@@ -1614,7 +1614,7 @@ static int sdebug_add_adapter()
printk(KERN_ERR "%s: out of memory at line %d\n", printk(KERN_ERR "%s: out of memory at line %d\n",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
error = -ENOMEM; error = -ENOMEM;
goto clean1; goto clean;
} }
memset(sdbg_devinfo, 0, sizeof(*sdbg_devinfo)); memset(sdbg_devinfo, 0, sizeof(*sdbg_devinfo));
sdbg_devinfo->sdbg_host = sdbg_host; sdbg_devinfo->sdbg_host = sdbg_host;
...@@ -1634,12 +1634,12 @@ static int sdebug_add_adapter() ...@@ -1634,12 +1634,12 @@ static int sdebug_add_adapter()
error = device_register(&sdbg_host->dev); error = device_register(&sdbg_host->dev);
if (error) if (error)
goto clean2; goto clean;
++scsi_debug_add_host; ++scsi_debug_add_host;
return error; return error;
clean2: clean:
list_for_each_safe(lh, lh_sf, &sdbg_host->dev_info_list) { list_for_each_safe(lh, lh_sf, &sdbg_host->dev_info_list) {
sdbg_devinfo = list_entry(lh, struct sdebug_dev_info, sdbg_devinfo = list_entry(lh, struct sdebug_dev_info,
dev_list); dev_list);
...@@ -1647,7 +1647,6 @@ static int sdebug_add_adapter() ...@@ -1647,7 +1647,6 @@ static int sdebug_add_adapter()
kfree(sdbg_devinfo); kfree(sdbg_devinfo);
} }
clean1:
kfree(sdbg_host); kfree(sdbg_host);
return error; return error;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment