qemu/hw/char
Pan Nengyuan 0d930b870a virtio-serial-bus: Plug memory leak on realize() error paths
We neglect to free port->bh on the error paths.  Fix that.
Reproducer:
    {'execute': 'device_add', 'arguments': {'id': 'virtio_serial_pci0', 'driver': 'virtio-serial-pci', 'bus': 'pci.0', 'addr': '0x5'}, 'id': 'yVkZcGgV'}
    {'execute': 'device_add', 'arguments': {'id': 'port1', 'driver': 'virtserialport', 'name': 'port1', 'chardev': 'channel1', 'bus': 'virtio_serial_pci0.0', 'nr': 1}, 'id': '3dXdUgJA'}
    {'execute': 'device_add', 'arguments': {'id': 'port2', 'driver': 'virtserialport', 'name': 'port2', 'chardev': 'channel2', 'bus': 'virtio_serial_pci0.0', 'nr': 1}, 'id': 'qLzcCkob'}
    {'execute': 'device_add', 'arguments': {'id': 'port2', 'driver': 'virtserialport', 'name': 'port2', 'chardev': 'channel2', 'bus': 'virtio_serial_pci0.0', 'nr': 2}, 'id': 'qLzcCkob'}

The leak stack:
Direct leak of 40 byte(s) in 1 object(s) allocated from:
    #0 0x7f04a8008ae8 in __interceptor_malloc (/lib64/libasan.so.5+0xefae8)
    #1 0x7f04a73cf1d5 in g_malloc (/lib64/libglib-2.0.so.0+0x531d5)
    #2 0x56273eaee484 in aio_bh_new /mnt/sdb/backup/qemu/util/async.c:125
    #3 0x56273eafe9a8 in qemu_bh_new /mnt/sdb/backup/qemu/util/main-loop.c:532
    #4 0x56273d52e62e in virtser_port_device_realize /mnt/sdb/backup/qemu/hw/char/virtio-serial-bus.c:946
    #5 0x56273dcc5040 in device_set_realized /mnt/sdb/backup/qemu/hw/core/qdev.c:891
    #6 0x56273e5ebbce in property_set_bool /mnt/sdb/backup/qemu/qom/object.c:2238
    #7 0x56273e5e5a9c in object_property_set /mnt/sdb/backup/qemu/qom/object.c:1324
    #8 0x56273e5ef5f8 in object_property_set_qobject /mnt/sdb/backup/qemu/qom/qom-qobject.c:26
    #9 0x56273e5e5e6a in object_property_set_bool /mnt/sdb/backup/qemu/qom/object.c:1390
    #10 0x56273daa40de in qdev_device_add /mnt/sdb/backup/qemu/qdev-monitor.c:680
    #11 0x56273daa53e9 in qmp_device_add /mnt/sdb/backup/qemu/qdev-monitor.c:805

Fixes: 199646d815
Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Amit Shah <amit@kernel.org>
Message-Id: <20200309021738.30072-1-pannengyuan@huawei.com>
Reviewed-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2020-03-29 06:33:47 -04:00
..
bcm2835_aux.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
cadence_uart.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
cmsdk-apb-uart.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
debugcon.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
digic-uart.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
escc.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
etraxfs_ser.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
exynos4210_uart.c hw/char/exynos4210_uart: Fix memleaks in exynos4210_uart_init 2020-02-13 14:14:55 +00:00
grlib_apbuart.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
imx_serial.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
ipoctal232.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
Kconfig hw/char: Move multi-serial devices into separate file 2019-05-17 15:19:39 +02:00
lm32_juart.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
lm32_uart.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
Makefile.objs hw/*/Makefile.objs: Move many .o files to common-objs 2020-02-04 09:00:57 +01:00
mcf_uart.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
milkymist-uart.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
nrf51_uart.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
omap_uart.c serial: start making SerialMM a sysbus device 2020-01-07 17:23:30 +04:00
parallel-isa.c Include hw/qdev-properties.h less 2019-08-16 13:31:53 +02:00
parallel.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
pl011.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
sclpconsole-lm.c misc: Replace zero-length arrays with flexible array member (manual) 2020-03-16 22:07:42 +01:00
sclpconsole.c misc: Replace zero-length arrays with flexible array member (manual) 2020-03-16 22:07:42 +01:00
serial-isa.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
serial-pci-multi.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
serial-pci.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
serial.c hw/char: Let devices own the MemoryRegion they create 2020-03-17 15:18:49 +01:00
sh_serial.c chardev: Use QEMUChrEvent enum in IOEventHandler typedef 2020-01-08 11:15:35 +01:00
spapr_vty.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
stm32f2xx_usart.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
terminal3270.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
trace-events hw/char/exynos4210_uart: Add receive DMA support 2020-01-23 16:34:15 +00:00
virtio-console.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
virtio-serial-bus.c virtio-serial-bus: Plug memory leak on realize() error paths 2020-03-29 06:33:47 -04:00
xen_console.c Include sysemu/sysemu.h a lot less 2019-08-16 13:31:53 +02:00
xilinx_uartlite.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00