From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: [PATCH 1/9] msix: avoid leaking kvm data on init failure Date: Mon, 20 Sep 2010 17:06:42 +0200 Message-ID: <1284995210-32432-2-git-send-email-avi@redhat.com> References: <1284995210-32432-1-git-send-email-avi@redhat.com> To: Marcelo Tosatti , kvm@vger.kernel.org, "Michael S. Tsirkin" Return-path: Received: from mx1.redhat.com ([209.132.183.28]:55169 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751844Ab0ITPGw (ORCPT ); Mon, 20 Sep 2010 11:06:52 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o8KF6qB6028724 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 20 Sep 2010 11:06:52 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o8KF6pPe018238 for ; Mon, 20 Sep 2010 11:06:51 -0400 In-Reply-To: <1284995210-32432-1-git-send-email-avi@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Move initialization after we're certain to succeed, so we don't leak memory on failure. Signed-off-by: Avi Kivity --- hw/msix.c | 13 +++++++------ 1 files changed, 7 insertions(+), 6 deletions(-) diff --git a/hw/msix.c b/hw/msix.c index 3dd0456..312439a 100644 --- a/hw/msix.c +++ b/hw/msix.c @@ -373,12 +373,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; @@ -400,6 +394,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.2.3