[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 06/12] hw/pci/pci.c: Don't leak PCIBus::irq_count[] in pci_bus_irq
From: |
Anthony PERARD |
Subject: |
[PULL 06/12] hw/pci/pci.c: Don't leak PCIBus::irq_count[] in pci_bus_irqs() |
Date: |
Wed, 7 Jun 2023 15:18:33 +0100 |
From: Bernhard Beschow <shentey@gmail.com>
When calling pci_bus_irqs() multiple times on the same object without calling
pci_bus_irqs_cleanup() in between PCIBus::irq_count[] is currently leaked.
Let's fix this because Xen will do just that in a few commits, and because
calling pci_bus_irqs_cleanup() in between seems fragile and cumbersome.
Note that pci_bus_irqs_cleanup() now has to NULL irq_count such that
pci_bus_irqs() doesn't do a double free.
Signed-off-by: Bernhard Beschow <shentey@gmail.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Chuck Zmudzinski <brchuckz@aol.com>
Message-Id: <20230403074124.3925-3-shentey@gmail.com>
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
hw/pci/pci.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 1cc7c89036..9b7b4d7c18 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -560,6 +560,7 @@ void pci_bus_irqs(PCIBus *bus, pci_set_irq_fn set_irq,
bus->set_irq = set_irq;
bus->irq_opaque = irq_opaque;
bus->nirq = nirq;
+ g_free(bus->irq_count);
bus->irq_count = g_malloc0(nirq * sizeof(bus->irq_count[0]));
}
@@ -575,6 +576,7 @@ void pci_bus_irqs_cleanup(PCIBus *bus)
bus->irq_opaque = NULL;
bus->nirq = 0;
g_free(bus->irq_count);
+ bus->irq_count = NULL;
}
PCIBus *pci_register_root_bus(DeviceState *parent, const char *name,
--
Anthony PERARD
- [PULL 00/12] xen queue, Anthony PERARD, 2023/06/07
- [PULL 02/12] hw/xen: Fix memory leak in libxenstore_open() for Xen, Anthony PERARD, 2023/06/07
- [PULL 03/12] xen: Drop support for Xen versions below 4.7.1, Anthony PERARD, 2023/06/07
- [PULL 06/12] hw/pci/pci.c: Don't leak PCIBus::irq_count[] in pci_bus_irqs(),
Anthony PERARD <=
- [PULL 04/12] hw/xen: Fix broken check for invalid state in xs_be_open(), Anthony PERARD, 2023/06/07
- [PULL 01/12] hw/xen: Simplify emulated Xen platform init, Anthony PERARD, 2023/06/07
- [PULL 07/12] hw/isa/piix3: Reuse piix3_realize() in piix3_xen_realize(), Anthony PERARD, 2023/06/07
- [PULL 09/12] hw/isa/piix3: Avoid Xen-specific variant of piix3_write_config(), Anthony PERARD, 2023/06/07
- [PULL 05/12] include/hw/xen/xen: Rename xen_piix3_set_irq() to xen_intx_set_irq(), Anthony PERARD, 2023/06/07
- [PULL 11/12] hw/isa/piix3: Resolve redundant TYPE_PIIX3_XEN_DEVICE, Anthony PERARD, 2023/06/07
- [PULL 12/12] xen-block: fix segv on unrealize, Anthony PERARD, 2023/06/07
- [PULL 08/12] hw/isa/piix3: Wire up Xen PCI IRQ handling outside of PIIX3, Anthony PERARD, 2023/06/07
- [PULL 10/12] hw/isa/piix3: Resolve redundant k->config_write assignments, Anthony PERARD, 2023/06/07
- Re: [PULL 00/12] xen queue, Michael Tokarev, 2023/06/07