From patchwork Wed Sep 16 01:11:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tiejun Chen X-Patchwork-Id: 518175 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 C3FD2140187 for ; Wed, 16 Sep 2015 11:11:47 +1000 (AEST) Received: from localhost ([::1]:46669 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zc1GD-0000WX-Do for incoming@patchwork.ozlabs.org; Tue, 15 Sep 2015 21:11:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44408) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zc1Fx-0000Fd-OD for qemu-devel@nongnu.org; Tue, 15 Sep 2015 21:11:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zc1Fs-0000Pm-QD for qemu-devel@nongnu.org; Tue, 15 Sep 2015 21:11:29 -0400 Received: from mga09.intel.com ([134.134.136.24]:60840) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zc1Fs-0000LC-KH for qemu-devel@nongnu.org; Tue, 15 Sep 2015 21:11:24 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 15 Sep 2015 18:11:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,537,1437462000"; d="scan'208";a="805309424" Received: from tiejunch-mobl1.ccr.corp.intel.com (HELO [10.238.130.65]) ([10.238.130.65]) by orsmga002.jf.intel.com with ESMTP; 15 Sep 2015 18:11:21 -0700 To: Paolo Bonzini , Stefano Stabellini References: <55F0DB30.6070607@intel.com> <55F14E20.6070805@intel.com> <55F69A18.20709@redhat.com> <55F7FA43.40600@redhat.com> From: "Chen, Tiejun" Message-ID: <55F8C1B8.6060509@intel.com> Date: Wed, 16 Sep 2015 09:11:20 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <55F7FA43.40600@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.24 Cc: Peter Maydell , "xen-devel@lists.xensource.com Devel" , QEMU Developers , mst@redhat.com Subject: Re: [Qemu-devel] [PULL 0/19] xen-2015-09-08-tag X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On 9/15/2015 7:00 PM, Paolo Bonzini wrote: > > > On 15/09/2015 11:55, Stefano Stabellini wrote: >> On Mon, 14 Sep 2015, Paolo Bonzini wrote: >>> > On 10/09/2015 12:29, Stefano Stabellini wrote: >>>> > > + if (lseek(config_fd, pos, SEEK_SET) != pos) { >>>> > > + return -errno; >>>> > > + } >>>> > > do { >>>> > > - rc = pread(config_fd, (uint8_t *)&val, len, pos); >>>> > > + rc = read(config_fd, (uint8_t *)&val, len); >>>> > > } while (rc < 0 && (errno == EINTR || errno == EAGAIN)); >>> > >>> > This leaks config_fd. >> I don't follow, it leaks config_fd where? > > Where lseek returns -errno (and IIRC in other places in the same function). Do you mean we need this change? Thanks Tiejun diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c index 1fb71c8..7d44228 100644 --- a/hw/pci-host/piix.c +++ b/hw/pci-host/piix.c @@ -775,15 +775,18 @@ static int host_pci_config_read(int pos, int len, uint32_t val) } if (lseek(config_fd, pos, SEEK_SET) != pos) { + close(config_fd); return -errno; } do { rc = read(config_fd, (uint8_t *)&val, len); } while (rc < 0 && (errno == EINTR || errno == EAGAIN)); if (rc != len) { + close(config_fd); return -errno; } + close(config_fd); return 0; }