From: Jesper Juhl Date: Wed, 16 Nov 2011 23:41:13 +0000 (+1100) Subject: drivers/scsi/aacraid/commctrl.c: fix mem leak in aac_send_raw_srb() X-Git-Tag: next-20111129~2^2~87 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=dc049ae29456ab91cf0e071cc2b024cd9eb1b65c;p=karo-tx-linux.git drivers/scsi/aacraid/commctrl.c: fix mem leak in aac_send_raw_srb() We leak in drivers/scsi/aacraid/commctrl.c::aac_send_raw_srb() : We allocate memory: ... struct user_sgmap* usg; usg = kmalloc(actual_fibsize - sizeof(struct aac_srb) + sizeof(struct sgmap), GFP_KERNEL); and then neglect to free it: ... for (i = 0; i < usg->count; i++) { u64 addr; void* p; if (usg->sg[i].count > ((dev->adapter_info.options & AAC_OPT_NEW_COMM) ? (dev->scsi_host_ptr->max_sectors << 9) : 65536)) { rcode = -EINVAL; goto cleanup; ... this 'goto' makes 'usg' go out of scope and leak the memory we allocated. Other exits properly kfree(usg), it's just here it is neglected. Signed-off-by: Jesper Juhl Cc: James Bottomley Signed-off-by: Andrew Morton --- diff --git a/drivers/scsi/aacraid/commctrl.c b/drivers/scsi/aacraid/commctrl.c index 8a0b33033177..0bd38da4ada0 100644 --- a/drivers/scsi/aacraid/commctrl.c +++ b/drivers/scsi/aacraid/commctrl.c @@ -650,6 +650,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) AAC_OPT_NEW_COMM) ? (dev->scsi_host_ptr->max_sectors << 9) : 65536)) { + kfree(usg); rcode = -EINVAL; goto cleanup; }