Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LpDTQ-0005zB-DQ for qemu-devel@nongnu.org; Wed, 01 Apr 2009 23:20:12 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LpDTL-0005wJ-JD for qemu-devel@nongnu.org; Wed, 01 Apr 2009 23:20:11 -0400 Received: from [199.232.76.173] (port=41586 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LpDTL-0005wB-De for qemu-devel@nongnu.org; Wed, 01 Apr 2009 23:20:07 -0400 Received: from main.gmane.org ([80.91.229.2]:42681 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LpDTL-0003KX-26 for qemu-devel@nongnu.org; Wed, 01 Apr 2009 23:20:07 -0400 Received: from root by ciao.gmane.org with local (Exim 4.43) id 1LpDTG-0007MB-Dv for qemu-devel@nongnu.org; Thu, 02 Apr 2009 03:20:02 +0000 Received: from c-71-202-202-194.hsd1.ca.comcast.net ([71.202.202.194]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 02 Apr 2009 03:20:02 +0000 Received: from nolan by c-71-202-202-194.hsd1.ca.comcast.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 02 Apr 2009 03:20:02 +0000 From: Nolan Date: Thu, 2 Apr 2009 03:18:20 +0000 (UTC) Message-ID: References: <1238634456.15350.595.camel@voxel> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: news Subject: [Qemu-devel] Re: [PATCH] [UPDATED] Add host_device support to qemu-img. Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org malc comtv.ru> writes: > On Wed, 1 Apr 2009, Nolan wrote: <... snip ...> > > + fd = open(filename, O_WRONLY | O_BINARY); > > + if (fd < 0) > > + return -EIO; > > + > > + if (fstat(fd, &stat_buf) < 0) > > + ret = -EIO; > > + else if (!S_ISBLK(stat_buf.st_mode)) > > + ret = -EIO; > > + else if (lseek(fd, 0, SEEK_END) < total_size * 512) > > + ret = -ENOSPC; > > This leaks fescriptors doesn't it, even if only user is qemu-img which > just exits on errors this still looks fragile. I don't see how. Once a valid fd is allocated, all paths out of this function pass through the close (now below this comment) right before the "return ret;". > > + > > + close(fd); > > + return ret; > > +} <... snip ...>