From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:51520) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TYYOG-0003PX-44 for qemu-devel@nongnu.org; Wed, 14 Nov 2012 03:32:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TYYOD-0001oL-1a for qemu-devel@nongnu.org; Wed, 14 Nov 2012 03:32:08 -0500 Received: from mail-ee0-f45.google.com ([74.125.83.45]:48874) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TYYOC-0001oC-RR for qemu-devel@nongnu.org; Wed, 14 Nov 2012 03:32:04 -0500 Received: by mail-ee0-f45.google.com with SMTP id d49so99854eek.4 for ; Wed, 14 Nov 2012 00:32:03 -0800 (PST) Date: Wed, 14 Nov 2012 09:32:01 +0100 From: Stefan Hajnoczi Message-ID: <20121114083201.GA23826@stefanha-thinkpad.redhat.com> References: <1352816095-14051-1-git-send-email-kwolf@redhat.com> <1352816095-14051-3-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1352816095-14051-3-git-send-email-kwolf@redhat.com> Subject: Re: [Qemu-devel] [PATCH 2/2] block: Avoid second open for format probing List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: qemu-devel@nongnu.org On Tue, Nov 13, 2012 at 03:14:55PM +0100, Kevin Wolf wrote: > @@ -691,12 +685,15 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename, > > /* Open the image, either directly or using a protocol */ > if (drv->bdrv_file_open) { > + if (file != NULL) { > + bdrv_swap(file, bs); > + bdrv_delete(file); > + } > ret = drv->bdrv_file_open(bs, filename, open_flags); > } else { [...] > /* Open the image */ > - ret = bdrv_open_common(bs, filename, flags, drv); > + ret = bdrv_open_common(bs, file, filename, flags, drv); > if (ret < 0) { > goto unlink_and_fail; > } > @@ -894,6 +895,9 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags, > return 0; > > unlink_and_fail: > + if (file != NULL) { > + bdrv_delete(file); > + } Not sure I understand this code path. We have a protocol (the driver implements .bdrv_file_open()) so we swap file and bs, then delete old bs. Then we call .bdrv_file_open() on the already open file BDS. Is it okay to call .bdrv_file_open() on an already open BDS? Now if .bdrv_file_open() fails we will bdrv_delete() the already deleted file BDS. This is a double-free. Stefan