qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Chenqun (kuhn)" <kuhn.chenqun@huawei.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	"i.mitsyanko@gmail.com" <i.mitsyanko@gmail.com>,
	"peter.maydell@linaro.org" <peter.maydell@linaro.org>
Cc: "qemu-trivial@nongnu.org" <qemu-trivial@nongnu.org>,
	Zhanghailiang <zhang.zhanghailiang@huawei.com>
Subject: RE: [PATCH] hw/char/exynos4210_uart: Fix memleaks in exynos4210_uart_init
Date: Wed, 12 Feb 2020 06:44:46 +0000	[thread overview]
Message-ID: <7412CDE03601674DA8197E2EBD8937E83B1163F4@dggemm531-mbx.china.huawei.com> (raw)
In-Reply-To: <ce5d39c0-d532-4b54-a39c-01c9c97cbb59@redhat.com>

>-----Original Message-----
>From: Philippe Mathieu-Daudé [mailto:philmd@redhat.com]
>Sent: Wednesday, February 12, 2020 2:16 PM
>To: Chenqun (kuhn) <kuhn.chenqun@huawei.com>; qemu-
>devel@nongnu.org; i.mitsyanko@gmail.com; peter.maydell@linaro.org
>Cc: qemu-trivial@nongnu.org; Zhanghailiang
><zhang.zhanghailiang@huawei.com>
>Subject: Re: [PATCH] hw/char/exynos4210_uart: Fix memleaks in
>exynos4210_uart_init
>
>On 2/12/20 4:36 AM, kuhn.chenqun@huawei.com wrote:
>> From: Chen Qun <kuhn.chenqun@huawei.com>
>>
>> It's easy to reproduce as follow:
>> virsh qemu-monitor-command vm1 --pretty '{"execute":
>> "device-list-properties", "arguments":{"typename":"exynos4210.uart"}}'
>>
>> ASAN shows memory leak stack:
>>    #1 0xfffd896d71cb in g_malloc0 (/lib64/libglib-2.0.so.0+0x571cb)
>>    #2 0xaaad270beee3 in timer_new_full /qemu/include/qemu/timer.h:530
>>    #3 0xaaad270beee3 in timer_new /qemu/include/qemu/timer.h:551
>>    #4 0xaaad270beee3 in timer_new_ns /qemu/include/qemu/timer.h:569
>>    #5 0xaaad270beee3 in exynos4210_uart_init
>/qemu/hw/char/exynos4210_uart.c:677
>>    #6 0xaaad275c8f4f in object_initialize_with_type /qemu/qom/object.c:516
>>    #7 0xaaad275c91bb in object_new_with_type /qemu/qom/object.c:684
>>    #8 0xaaad2755df2f in qmp_device_list_properties
>> /qemu/qom/qom-qmp-cmds.c:152
>>
>> Reported-by: Euler Robot <euler.robot@huawei.com>
>> Signed-off-by: Chen Qun <kuhn.chenqun@huawei.com>
>> ---
>>   hw/char/exynos4210_uart.c | 8 ++++----
>>   1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/hw/char/exynos4210_uart.c b/hw/char/exynos4210_uart.c
>> index 25d6588e41..5048db5410 100644
>> --- a/hw/char/exynos4210_uart.c
>> +++ b/hw/char/exynos4210_uart.c
>> @@ -674,10 +674,6 @@ static void exynos4210_uart_init(Object *obj)
>>       SysBusDevice *dev = SYS_BUS_DEVICE(obj);
>>       Exynos4210UartState *s = EXYNOS4210_UART(dev);
>>
>> -    s->fifo_timeout_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
>> -                                         exynos4210_uart_timeout_int, s);
>> -    s->wordtime = NANOSECONDS_PER_SECOND * 10 / 9600;
>
>Why are you moving s->wordtime from init() to realize()?
>
Hi  Philippe,  thanks for your reply!

Because I found the variable wordtime is usually used with fifo_timeout_timer.   
Eg, they are used together in the exynos4210_uart_rx_timeout_set function.

I didn't find anything wrong with wordtime in the realize().  
Does it have any other effects?

Thanks.
>> -
>>       /* memory mapping */
>>       memory_region_init_io(&s->iomem, obj, &exynos4210_uart_ops, s,
>>                             "exynos4210.uart",
>> EXYNOS4210_UART_REGS_MEM_SIZE); @@ -691,6 +687,10 @@ static void
>exynos4210_uart_realize(DeviceState *dev, Error **errp)
>>   {
>>       Exynos4210UartState *s = EXYNOS4210_UART(dev);
>>
>> +    s->fifo_timeout_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
>> +                                         exynos4210_uart_timeout_int, s);
>> +    s->wordtime = NANOSECONDS_PER_SECOND * 10 / 9600;
>> +
>>       qemu_chr_fe_set_handlers(&s->chr, exynos4210_uart_can_receive,
>>                                exynos4210_uart_receive, exynos4210_uart_event,
>>                                NULL, s, NULL, true);
>>


  reply	other threads:[~2020-02-12  6:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-12  3:36 [PATCH] hw/char/exynos4210_uart: Fix memleaks in exynos4210_uart_init kuhn.chenqun
2020-02-12  6:16 ` Philippe Mathieu-Daudé
2020-02-12  6:44   ` Chenqun (kuhn) [this message]
2020-02-12  7:39     ` Philippe Mathieu-Daudé
2020-02-12 16:19       ` Eduardo Habkost
2020-02-13  2:10         ` Chenqun (kuhn)
2020-02-13 14:28         ` Markus Armbruster
2020-02-13 16:32           ` Philippe Mathieu-Daudé
2020-02-13 16:37             ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7412CDE03601674DA8197E2EBD8937E83B1163F4@dggemm531-mbx.china.huawei.com \
    --to=kuhn.chenqun@huawei.com \
    --cc=i.mitsyanko@gmail.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=zhang.zhanghailiang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).