Skip to content

Commit

Permalink
hw/char/exynos4210_uart: Fix memleaks in exynos4210_uart_init
Browse files Browse the repository at this point in the history
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:
  kata-containers#1 0xfffd896d71cb in g_malloc0 (/lib64/libglib-2.0.so.0+0x571cb)
  kata-containers#2 0xaaad270beee3 in timer_new_full /qemu/include/qemu/timer.h:530
  kata-containers#3 0xaaad270beee3 in timer_new /qemu/include/qemu/timer.h:551
  kata-containers#4 0xaaad270beee3 in timer_new_ns /qemu/include/qemu/timer.h:569
  kata-containers#5 0xaaad270beee3 in exynos4210_uart_init /qemu/hw/char/exynos4210_uart.c:677
  kata-containers#6 0xaaad275c8f4f in object_initialize_with_type /qemu/qom/object.c:516
  kata-containers#7 0xaaad275c91bb in object_new_with_type /qemu/qom/object.c:684
  kata-containers#8 0xaaad2755df2f in qmp_device_list_properties /qemu/qom/qom-qmp-cmds.c:152

Reported-by: Euler Robot <[email protected]>
Signed-off-by: Chen Qun <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-id: [email protected]
Signed-off-by: Peter Maydell <[email protected]>
  • Loading branch information
Kuhn-Chen authored and pm215 committed Feb 13, 2020
1 parent 917940c commit 8bbc394
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions hw/char/exynos4210_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +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;

/* memory mapping */
Expand All @@ -691,6 +689,9 @@ 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);

qemu_chr_fe_set_handlers(&s->chr, exynos4210_uart_can_receive,
exynos4210_uart_receive, exynos4210_uart_event,
NULL, s, NULL, true);
Expand Down

0 comments on commit 8bbc394

Please sign in to comment.