This commit adds failback routine for `virtio_pci_realize` to fix the memory leak of an address space and the virtio-net device object. If the realization of the device failed, the address space should be destroyed too.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2845 Signed-off-by: Zheng Huang <hz1624917...@outlook.com> --- hw/virtio/virtio-pci.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index c773a9130c..4b0d8cd90a 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -2266,6 +2266,9 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp) virtio_pci_bus_new(&proxy->bus, sizeof(proxy->bus), proxy); if (k->realize) { k->realize(proxy, errp); + if (*errp) { + address_space_destroy(&proxy->modern_cfg_mem_as); + } } } -- 2.34.1