diff mbox

serial: fix memory leak in serial exit

Message ID 586cb5ab.f31d9d0a.38ac3.acf2@mx.google.com (mailing list archive)
State New, archived
Headers show

Commit Message

Li Qiang Jan. 4, 2017, 8:43 a.m. UTC
From: Li Qiang <liqiang6-s@360.cn>

The serial_exit_core function doesn't free some resources.
This can lead memory leak when hotplug and unplug. This
patch avoid this.

Signed-off-by: Li Qiang <liqiang6-s@360.cn>
---
 hw/char/serial.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Paolo Bonzini Jan. 4, 2017, 11:43 a.m. UTC | #1
On 04/01/2017 09:43, Li Qiang wrote:
> From: Li Qiang <liqiang6-s@360.cn>
> 
> The serial_exit_core function doesn't free some resources.
> This can lead memory leak when hotplug and unplug. This
> patch avoid this.
> 
> Signed-off-by: Li Qiang <liqiang6-s@360.cn>
> ---
>  hw/char/serial.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/hw/char/serial.c b/hw/char/serial.c
> index ffbacd8..67b18ed 100644
> --- a/hw/char/serial.c
> +++ b/hw/char/serial.c
> @@ -906,6 +906,16 @@ void serial_realize_core(SerialState *s, Error **errp)
>  void serial_exit_core(SerialState *s)
>  {
>      qemu_chr_fe_deinit(&s->chr);
> +
> +    timer_del(s->modem_status_poll);
> +    timer_free(s->modem_status_poll);
> +
> +    timer_del(s->fifo_timeout_timer);
> +    timer_free(s->fifo_timeout_timer);
> +
> +    fifo8_destroy(&s->recv_fifo);
> +    fifo8_destroy(&s->xmit_fifo);
> +
>      qemu_unregister_reset(serial_reset, s);
>  }
>  
> 

Thanks, looks good.

Paolo
Michael S. Tsirkin Jan. 4, 2017, 1:24 p.m. UTC | #2
On Wed, Jan 04, 2017 at 12:43:35PM +0100, Paolo Bonzini wrote:
> 
> 
> On 04/01/2017 09:43, Li Qiang wrote:
> > From: Li Qiang <liqiang6-s@360.cn>
> > 
> > The serial_exit_core function doesn't free some resources.
> > This can lead memory leak when hotplug and unplug. This
> > patch avoid this.
> > 
> > Signed-off-by: Li Qiang <liqiang6-s@360.cn>
> > ---
> >  hw/char/serial.c | 10 ++++++++++
> >  1 file changed, 10 insertions(+)
> > 
> > diff --git a/hw/char/serial.c b/hw/char/serial.c
> > index ffbacd8..67b18ed 100644
> > --- a/hw/char/serial.c
> > +++ b/hw/char/serial.c
> > @@ -906,6 +906,16 @@ void serial_realize_core(SerialState *s, Error **errp)
> >  void serial_exit_core(SerialState *s)
> >  {
> >      qemu_chr_fe_deinit(&s->chr);
> > +
> > +    timer_del(s->modem_status_poll);
> > +    timer_free(s->modem_status_poll);
> > +
> > +    timer_del(s->fifo_timeout_timer);
> > +    timer_free(s->fifo_timeout_timer);
> > +
> > +    fifo8_destroy(&s->recv_fifo);
> > +    fifo8_destroy(&s->xmit_fifo);
> > +
> >      qemu_unregister_reset(serial_reset, s);
> >  }
> >  
> > 
> 
> Thanks, looks good.
> 
> Paolo


Paolo, so are you merging this?

Acked-by: Michael S. Tsirkin <mst@redhat.com>
Paolo Bonzini Jan. 5, 2017, 10:17 a.m. UTC | #3
On 04/01/2017 14:24, Michael S. Tsirkin wrote:
> On Wed, Jan 04, 2017 at 12:43:35PM +0100, Paolo Bonzini wrote:
>>
>>
>> On 04/01/2017 09:43, Li Qiang wrote:
>>> From: Li Qiang <liqiang6-s@360.cn>
>>>
>>> The serial_exit_core function doesn't free some resources.
>>> This can lead memory leak when hotplug and unplug. This
>>> patch avoid this.
>>>
>>> Signed-off-by: Li Qiang <liqiang6-s@360.cn>
>>> ---
>>>  hw/char/serial.c | 10 ++++++++++
>>>  1 file changed, 10 insertions(+)
>>>
>>> diff --git a/hw/char/serial.c b/hw/char/serial.c
>>> index ffbacd8..67b18ed 100644
>>> --- a/hw/char/serial.c
>>> +++ b/hw/char/serial.c
>>> @@ -906,6 +906,16 @@ void serial_realize_core(SerialState *s, Error **errp)
>>>  void serial_exit_core(SerialState *s)
>>>  {
>>>      qemu_chr_fe_deinit(&s->chr);
>>> +
>>> +    timer_del(s->modem_status_poll);
>>> +    timer_free(s->modem_status_poll);
>>> +
>>> +    timer_del(s->fifo_timeout_timer);
>>> +    timer_free(s->fifo_timeout_timer);
>>> +
>>> +    fifo8_destroy(&s->recv_fifo);
>>> +    fifo8_destroy(&s->xmit_fifo);
>>> +
>>>      qemu_unregister_reset(serial_reset, s);
>>>  }
>>>  
>>>
>>
>> Thanks, looks good.
>>
>> Paolo
> 
> 
> Paolo, so are you merging this?
> 
> Acked-by: Michael S. Tsirkin <mst@redhat.com>

Yes, thanks.

Paolo
diff mbox

Patch

diff --git a/hw/char/serial.c b/hw/char/serial.c
index ffbacd8..67b18ed 100644
--- a/hw/char/serial.c
+++ b/hw/char/serial.c
@@ -906,6 +906,16 @@  void serial_realize_core(SerialState *s, Error **errp)
 void serial_exit_core(SerialState *s)
 {
     qemu_chr_fe_deinit(&s->chr);
+
+    timer_del(s->modem_status_poll);
+    timer_free(s->modem_status_poll);
+
+    timer_del(s->fifo_timeout_timer);
+    timer_free(s->fifo_timeout_timer);
+
+    fifo8_destroy(&s->recv_fifo);
+    fifo8_destroy(&s->xmit_fifo);
+
     qemu_unregister_reset(serial_reset, s);
 }