From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=59630 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OOUNT-0001UP-1a for qemu-devel@nongnu.org; Tue, 15 Jun 2010 07:32:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OOUMt-0001S9-Kb for qemu-devel@nongnu.org; Tue, 15 Jun 2010 07:31:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56185) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OOUMt-0001Rx-BX for qemu-devel@nongnu.org; Tue, 15 Jun 2010 07:31:47 -0400 Message-ID: <4C176494.9000702@redhat.com> Date: Tue, 15 Jun 2010 13:31:32 +0200 From: Kevin Wolf MIME-Version: 1.0 Subject: Re: [Qemu-devel] Re: [PATCH v2 1/2] qcow2: Simplify image creation References: <1276598178-16798-1-git-send-email-kwolf@redhat.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: qemu-devel@nongnu.org Am 15.06.2010 13:08, schrieb Stefan Hajnoczi: > On Tue, Jun 15, 2010 at 11:36 AM, Kevin Wolf wrote: >> + /* >> + * And now open the image and make it consistent first (i.e. increase the >> + * refcount of the cluster that is occupied by the header and the refcount >> + * table) >> + */ >> + BlockDriver* drv = bdrv_find_format("qcow2"); >> + assert(drv != NULL); >> + ret = bdrv_open(bs, filename, BDRV_O_RDWR | BDRV_O_NO_FLUSH, drv); >> + if (ret < 0) { >> + goto out; >> + } > > Here I think we should really return directly on error. > bdrv_delete(bs) doesn't work since bs isn't initialized when > bdrv_open() fails. I did consider returning directly here at first, but decided against it because usually you expect that a function that uses some goto does so consistently. Also, I noticed later that returning directly we would leak the BlockDriverState which is malloc'd in bdrv_file_open. bs should still be initialized at this point and bs->drv = NULL after the bdrv_close() above, so that bdrv_delete(bs) will just free the BlockDriverState. Kevin