2013-09-26 02:03:10

by vaughan

[permalink] [raw]
Subject: Re: [PATCH] sg: fix memory leak

On 09/25/2013 10:26 PM, Vegard Nossum wrote:
> Commit e32c9e6300e3af659cbfe45e90a1e7dcd3572ada introduced a memory
> leak. Fix it.
>
> Cc: [email protected]
> Cc: Vaughan Cao <[email protected]>
> Cc: Douglas Gilbert <[email protected]>
> Signed-off-by: Vegard Nossum <[email protected]>
> ---
> drivers/scsi/sg.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
> index 5cbc4bb..a97143f 100644
> --- a/drivers/scsi/sg.c
> +++ b/drivers/scsi/sg.c
> @@ -2060,6 +2060,7 @@ sg_add_sfp(Sg_device * sdp, int dev)
> spin_lock_irqsave(&sdp->sfd_lock, iflags);
> if (sdp->detached) {
> spin_unlock_irqrestore(&sdp->sfd_lock, iflags);
> + kfree(sfp);
> return ERR_PTR(-ENODEV);
> }
> list_add_tail(&sfp->sfd_siblings, &sdp->sfds);
You're right. It's a memory leak.

Vaughan


2013-09-26 04:31:50

by Douglas Gilbert

[permalink] [raw]
Subject: Re: [PATCH] sg: fix memory leak

On 13-09-25 10:05 PM, vaughan wrote:
> On 09/25/2013 10:26 PM, Vegard Nossum wrote:
>> Commit e32c9e6300e3af659cbfe45e90a1e7dcd3572ada introduced a memory
>> leak. Fix it.
>>
>> Cc: [email protected]
>> Cc: Vaughan Cao <[email protected]>
>> Cc: Douglas Gilbert <[email protected]>
>> Signed-off-by: Vegard Nossum <[email protected]>
>> ---
>> drivers/scsi/sg.c | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
>> index 5cbc4bb..a97143f 100644
>> --- a/drivers/scsi/sg.c
>> +++ b/drivers/scsi/sg.c
>> @@ -2060,6 +2060,7 @@ sg_add_sfp(Sg_device * sdp, int dev)
>> spin_lock_irqsave(&sdp->sfd_lock, iflags);
>> if (sdp->detached) {
>> spin_unlock_irqrestore(&sdp->sfd_lock, iflags);
>> + kfree(sfp);
>> return ERR_PTR(-ENODEV);
>> }
>> list_add_tail(&sfp->sfd_siblings, &sdp->sfds);
> You're right. It's a memory leak.

Signed-off-by: Douglas Gilbert <[email protected]>


There also a memory leak at the second 'return NULL;'
in dev_seq_start() .