[PATCH] SCSI, target, loopback: Fix memory leak intcm_loop_make_scsi_hba()

From: Jesper Juhl
Date: Thu Apr 07 2011 - 15:14:15 EST


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 fixes the leak.

Signed-off-by: Jesper Juhl <jj@xxxxxxxxxxxxx>
---
tcm_loop.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

compile tested only.

diff --git a/drivers/target/loopback/tcm_loop.c b/drivers/target/loopback/tcm_loop.c
index aed4e46..c4f81ec 100644
--- a/drivers/target/loopback/tcm_loop.c
+++ b/drivers/target/loopback/tcm_loop.c
@@ -1330,7 +1330,8 @@ struct se_wwn *tcm_loop_make_scsi_hba(

printk(KERN_ERR "Unable to locate prefix for emulated Target Port:"
" %s\n", name);
- return ERR_PTR(-EINVAL);
+ ret = -EINVAL;
+ goto out;

check_len:
if (strlen(name) > TL_WWN_ADDR_LEN) {


--
Jesper Juhl <jj@xxxxxxxxxxxxx> http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/