From patchwork Mon Jul 24 18:27:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 792968 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="U+TPXkIm"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xGVVH6F16z9s3T for ; Tue, 25 Jul 2017 04:37:43 +1000 (AEST) Received: from localhost ([::1]:56357 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dZiEf-0007K7-Hz for incoming@patchwork.ozlabs.org; Mon, 24 Jul 2017 14:37:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50369) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dZi65-0000Gm-Px for qemu-devel@nongnu.org; Mon, 24 Jul 2017 14:28:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dZi65-0004uu-1Z for qemu-devel@nongnu.org; Mon, 24 Jul 2017 14:28:49 -0400 Received: from mail-qt0-x243.google.com ([2607:f8b0:400d:c0d::243]:34205) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dZi64-0004uf-TO; Mon, 24 Jul 2017 14:28:48 -0400 Received: by mail-qt0-x243.google.com with SMTP id i19so2261220qte.1; Mon, 24 Jul 2017 11:28:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6db8O8rUvq+dHdRRjGRWbj4pl1d1APVvxTg8Ajne3GE=; b=U+TPXkImdmSSfweG9kANIqTE50nC0VAiaUJkNJG/AgFJWwq+rurNyr7qTq3doUIakR Rh3sUsXPywO4UmPGrEYIniSgfvmLmVq2v9B0oQkeYQh2VH1CmlGNjB4BPwb8cJ2DwocX rnIzpIsrDOhO0Y4HiFI6b2mziFuj+HM84LJkIE9EJ6YF/fjjY/O05gnKFWbTrV8v6aEf VsLUCPqEMHs3GH9xbBTFzTYIOqhl6BkZC1AwUs01qaOMsGoXy/6VA0kB+xOkzxPQhu6i dYw15d3r2RE62G03HiiVsY/Y+5ojvUboDM4USr4Cq+gpAt7RD4OaQUVWr09WQtgbTe4r Iz7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=6db8O8rUvq+dHdRRjGRWbj4pl1d1APVvxTg8Ajne3GE=; b=MH7py7pbKMSA1v1b+8Uu+GF4Jz1V/STpGXa/wImLNAF45khOCdei6oijPjGNhmVrzG bK7CFoZ79TlS2rr181LgQr0ekYWv6dejdSbUvULM9zax4oR9y9DBuQGwDg66Yx8IYjuW tRsi2ER0Ya2W7H2HEC4MhqUiOi+eAekvzEMpSO6edXcZuYcOhT1Q+fnQ0rFo26WxwM4N 6bnl2FaEcypjCDxzKECQYw5xAGe88EP7JozZt3SsRDviP5/baiLwRJpz6sChdbmrywMZ KQUnZQTExQRJH/K/9rkbID1TP8oj+OQq/ixPJ7D2iZXe5fgjNhCySPQHTwbrg/RDluH/ YKeg== X-Gm-Message-State: AIVw111g1G2EZgt5UJQ0Y/+v/yAGpoPlwOhVoXL5pxThrKtATyazxii2 FSnPVEFZFwqY4Q== X-Received: by 10.237.63.162 with SMTP id s31mr17926589qth.206.1500920928449; Mon, 24 Jul 2017 11:28:48 -0700 (PDT) Received: from yoga.offpageads.com ([138.117.48.223]) by smtp.gmail.com with ESMTPSA id t57sm9033799qtt.18.2017.07.24.11.28.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Jul 2017 11:28:47 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Eric Blake , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Alex Williamson Date: Mon, 24 Jul 2017 15:27:29 -0300 Message-Id: <20170724182751.18261-14-f4bug@amsat.org> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170724182751.18261-1-f4bug@amsat.org> References: <20170724182751.18261-1-f4bug@amsat.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::243 Subject: [Qemu-devel] [PATCH for 2.10 13/35] vfio/pci: fix use of freed memory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" hw/vfio/pci.c:308:29: warning: Use of memory after it is freed qemu_set_fd_handler(*pfd, NULL, NULL, vdev); ^~~~ Reported-by: Clang Static Analyzer Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Paolo Bonzini --- hw/vfio/pci.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index d4051cb951..31e1edf447 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -257,7 +257,7 @@ static void vfio_intx_update(PCIDevice *pdev) static int vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp) { uint8_t pin = vfio_pci_read_config(&vdev->pdev, PCI_INTERRUPT_PIN, 1); - int ret, argsz; + int ret, argsz, retval = 0; struct vfio_irq_set *irq_set; int32_t *pfd; Error *err = NULL; @@ -302,12 +302,12 @@ static int vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp) qemu_set_fd_handler(*pfd, vfio_intx_interrupt, NULL, vdev); ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_SET_IRQS, irq_set); - g_free(irq_set); if (ret) { error_setg_errno(errp, -ret, "failed to setup INTx fd"); qemu_set_fd_handler(*pfd, NULL, NULL, vdev); event_notifier_cleanup(&vdev->intx.interrupt); - return -errno; + retval = -errno; + goto cleanup; } vfio_intx_enable_kvm(vdev, &err); @@ -319,7 +319,10 @@ static int vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp) trace_vfio_intx_enable(vdev->vbasedev.name); - return 0; +cleanup: + g_free(irq_set); + + return retval; } static void vfio_intx_disable(VFIOPCIDevice *vdev)