Re: [PATCH] tty/n_gsm.c: fix a memory leak in gsmld_open

From: Jiri Slaby
Date: Mon Jul 28 2014 - 08:11:51 EST


On 07/28/2014 01:32 PM, xinhui.pan wrote:
> ä 2014å07æ28æ 17:03, xinhui.pan åé:
>> Hi, Jiri
>>
>> ä 2014å07æ28æ 16:49, Jiri Slaby åé:
>>> On 07/28/2014 10:14 AM, xinhui.pan wrote:
>>>> If gsmld_attach_gsm fails, the gsm is not used anymore.
>>>> tty core will not call gsmld_close to do the cleanup work.
>>>> tty core just restore to the tty old ldisc.
>>>> That always causes memory leak.
>>>
>>> Nice catch!
>>>
>>>> --- a/drivers/tty/n_gsm.c
>>>> +++ b/drivers/tty/n_gsm.c
>>>> @@ -2382,7 +2383,13 @@ static int gsmld_open(struct tty_struct *tty)
>>>>
>>>> /* Attach the initial passive connection */
>>>> gsm->encoding = 1;
>>>> - return gsmld_attach_gsm(tty, gsm);
>>>> +
>>>> + ret = gsmld_attach_gsm(tty, gsm);
>>>> + if (ret != 0) {
>>>> + gsm_cleanup_mux(gsm);
>>>> + mux_put(gsm);
>>>
>>> It is quite illogical to put the mux here. It should be in gsmld_open.
>>> I.e. gsm_cleanup_mux here, mux_put there.
>>>
>>
>> Thanks for your reply :)
>> But I am a little confused with your comments, could you explain it when you are free?
>> Sorry for my poor English.
>>
>
> hi, Jiri
> I guess you want gsm_cleanup_mux() called in gsmld_attach_gsm(), just after gsm_activate_mux() fails?
> Yes, that seems really make sence. :)

Oh, I don't know what made me think you are changing gsmld_attach_gsm. I
misread the patch.

So in the end, your patch looks fine to me.

thanks,
--
js
suse labs
--
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/