Commit a57b5d36 authored by Jesper Juhl's avatar Jesper Juhl Committed by Nicholas Bellinger

loopback: Fix memory leak in tcm_loop_make_scsi_hba()

There is a memory leak in tcm_loop_make_scsi_hba().

If all the strstr() calls return NULL and we end up at return ERR_PTR(-EINVAL);
then we'll be leaking the memory previously allocated to tl_hba as
that variable goes out of scope.

This patch should fix the leak.
Signed-off-by: default avatarJesper Juhl <jj@chaosbits.net>
Signed-off-by: default avatarDan Carpenter <error27@gmail.com>
Signed-off-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
parent 824cc5ff
...@@ -1288,22 +1288,21 @@ struct se_wwn *tcm_loop_make_scsi_hba( ...@@ -1288,22 +1288,21 @@ struct se_wwn *tcm_loop_make_scsi_hba(
goto check_len; goto check_len;
} }
ptr = strstr(name, "iqn."); ptr = strstr(name, "iqn.");
if (ptr) { if (!ptr) {
tl_hba->tl_proto_id = SCSI_PROTOCOL_ISCSI; printk(KERN_ERR "Unable to locate prefix for emulated Target "
goto check_len; "Port: %s\n", name);
ret = -EINVAL;
goto out;
} }
tl_hba->tl_proto_id = SCSI_PROTOCOL_ISCSI;
printk(KERN_ERR "Unable to locate prefix for emulated Target Port:"
" %s\n", name);
return ERR_PTR(-EINVAL);
check_len: check_len:
if (strlen(name) >= TL_WWN_ADDR_LEN) { if (strlen(name) >= TL_WWN_ADDR_LEN) {
printk(KERN_ERR "Emulated NAA %s Address: %s, exceeds" printk(KERN_ERR "Emulated NAA %s Address: %s, exceeds"
" max: %d\n", name, tcm_loop_dump_proto_id(tl_hba), " max: %d\n", name, tcm_loop_dump_proto_id(tl_hba),
TL_WWN_ADDR_LEN); TL_WWN_ADDR_LEN);
kfree(tl_hba); ret = -EINVAL;
return ERR_PTR(-EINVAL); goto out;
} }
snprintf(&tl_hba->tl_wwn_address[0], TL_WWN_ADDR_LEN, "%s", &name[off]); snprintf(&tl_hba->tl_wwn_address[0], TL_WWN_ADDR_LEN, "%s", &name[off]);
......
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