From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35749) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZoqdN-00077i-VU for qemu-devel@nongnu.org; Wed, 21 Oct 2015 06:28:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZoqdN-0006p1-5r for qemu-devel@nongnu.org; Wed, 21 Oct 2015 06:28:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47326) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZoqdM-0006oW-Uu for qemu-devel@nongnu.org; Wed, 21 Oct 2015 06:28:41 -0400 Date: Wed, 21 Oct 2015 13:28:37 +0300 From: "Michael S. Tsirkin" Message-ID: <1445423133-5119-36-git-send-email-mst@redhat.com> References: <1445423133-5119-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1445423133-5119-1-git-send-email-mst@redhat.com> Subject: [Qemu-devel] [PULL 35/38] piix: fix resource leak reported by Coverity List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , zhanghailiang , Stefan Hajnoczi From: zhanghailiang config_fd should be closed before return, or there will be a resource leak error. Signed-off-by: zhanghailiang Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Stefan Hajnoczi --- hw/pci-host/piix.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c index 1fb71c8..7b2fbf9 100644 --- a/hw/pci-host/piix.c +++ b/hw/pci-host/piix.c @@ -764,6 +764,7 @@ static int host_pci_config_read(int pos, int len, uint32_t val) /* Access real host bridge. */ int rc = snprintf(path, size, "/sys/bus/pci/devices/%04x:%02x:%02x.%d/%s", 0, 0, 0, 0, "config"); + int ret = 0; if (rc >= size || rc < 0) { return -ENODEV; @@ -775,16 +776,18 @@ static int host_pci_config_read(int pos, int len, uint32_t val) } if (lseek(config_fd, pos, SEEK_SET) != pos) { - return -errno; + ret = -errno; + goto out; } do { rc = read(config_fd, (uint8_t *)&val, len); } while (rc < 0 && (errno == EINTR || errno == EAGAIN)); if (rc != len) { - return -errno; + ret = -errno; } - - return 0; +out: + close(config_fd); + return ret; } static int igd_pt_i440fx_initfn(struct PCIDevice *pci_dev) -- MST