Move initialization after we're certain to succeed, so we don't leak memory on failure. Signed-off-by: Avi Kivity <avi@xxxxxxxxxx> --- hw/msix.c | 13 +++++++------ 1 files changed, 7 insertions(+), 6 deletions(-) diff --git a/hw/msix.c b/hw/msix.c index 9663b17..162faa7 100644 --- a/hw/msix.c +++ b/hw/msix.c @@ -374,12 +374,6 @@ int msix_init(struct PCIDevice *dev, unsigned short nentries, if (nentries > MSIX_MAX_ENTRIES) return -EINVAL; -#ifdef KVM_CAP_IRQCHIP - if (kvm_enabled() && kvm_irqchip_in_kernel()) { - dev->msix_irq_entries = qemu_malloc(nentries * - sizeof *dev->msix_irq_entries); - } -#endif dev->msix_mask_notifier_opaque = qemu_mallocz(nentries * sizeof *dev->msix_mask_notifier_opaque); dev->msix_mask_notifier = NULL; @@ -401,6 +395,13 @@ int msix_init(struct PCIDevice *dev, unsigned short nentries, if (ret) goto err_config; +#ifdef KVM_CAP_IRQCHIP + if (kvm_enabled() && kvm_irqchip_in_kernel()) { + dev->msix_irq_entries = qemu_malloc(nentries * + sizeof *dev->msix_irq_entries); + } +#endif + dev->cap_present |= QEMU_PCI_CAP_MSIX; return 0; -- 1.7.3.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html