[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v4 2/7] hw/pci/pci.c: Don't leak PCIBus::irq_count[] in pci_b
From: |
Michael S. Tsirkin |
Subject: |
Re: [PATCH v4 2/7] hw/pci/pci.c: Don't leak PCIBus::irq_count[] in pci_bus_irqs() |
Date: |
Fri, 21 Apr 2023 03:37:46 -0400 |
On Mon, Apr 03, 2023 at 09:41:19AM +0200, Bernhard Beschow wrote:
> 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>
ok
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> hw/pci/pci.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index def5000e7b..be1c5d16ec 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -558,6 +558,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]));
> }
>
> @@ -573,6 +574,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,
> --
> 2.40.0
- [PATCH v4 0/7] Resolve TYPE_PIIX3_XEN_DEVICE, Bernhard Beschow, 2023/04/03
- [PATCH v4 1/7] include/hw/xen/xen: Rename xen_piix3_set_irq() to xen_intx_set_irq(), Bernhard Beschow, 2023/04/03
- [PATCH v4 2/7] hw/pci/pci.c: Don't leak PCIBus::irq_count[] in pci_bus_irqs(), Bernhard Beschow, 2023/04/03
- [PATCH v4 7/7] hw/isa/piix3: Resolve redundant TYPE_PIIX3_XEN_DEVICE, Bernhard Beschow, 2023/04/03
- [PATCH v4 3/7] hw/isa/piix3: Reuse piix3_realize() in piix3_xen_realize(), Bernhard Beschow, 2023/04/03
- [PATCH v4 4/7] hw/isa/piix3: Wire up Xen PCI IRQ handling outside of PIIX3, Bernhard Beschow, 2023/04/03
- [PATCH v4 5/7] hw/isa/piix3: Avoid Xen-specific variant of piix3_write_config(), Bernhard Beschow, 2023/04/03
- [PATCH v4 6/7] hw/isa/piix3: Resolve redundant k->config_write assignments, Bernhard Beschow, 2023/04/03
- Re: [PATCH v4 0/7] Resolve TYPE_PIIX3_XEN_DEVICE, Michael S. Tsirkin, 2023/04/21