From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59479) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UzMon-0003FY-Ff for qemu-devel@nongnu.org; Wed, 17 Jul 2013 04:10:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UzMof-0007wi-4j for qemu-devel@nongnu.org; Wed, 17 Jul 2013 04:10:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31014) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UzMoe-0007wX-Ph for qemu-devel@nongnu.org; Wed, 17 Jul 2013 04:10:28 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r6H8ASYu028354 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 17 Jul 2013 04:10:28 -0400 Message-ID: <51E65206.8040104@redhat.com> Date: Wed, 17 Jul 2013 10:12:54 +0200 From: Laszlo Ersek MIME-Version: 1.0 References: <1374045145-2278-1-git-send-email-famz@redhat.com> In-Reply-To: <1374045145-2278-1-git-send-email-famz@redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] block: fix vvfat s->qcow leak on error List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: kwolf@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com On 07/17/13 09:12, Fam Zheng wrote: > s->qcow is allocated but not freed if bdrv_open fails. Fix the possible > leak, remove unnecessary check for bdrv_new(), honor error code of > bdrv_create(). > > Signed-off-by: Fam Zheng > --- > block/vvfat.c | 12 ++++++------ > 1 file changed, 6 insertions(+), 6 deletions(-) > > diff --git a/block/vvfat.c b/block/vvfat.c > index 87b0279..733f382 100644 > --- a/block/vvfat.c > +++ b/block/vvfat.c > @@ -2927,18 +2927,18 @@ static int enable_write_target(BDRVVVFATState *s) > set_option_parameter_int(options, BLOCK_OPT_SIZE, s->sector_count * 512); > set_option_parameter(options, BLOCK_OPT_BACKING_FILE, "fat:"); > > - if (bdrv_create(bdrv_qcow, s->qcow_filename, options) < 0) > - return -1; > + ret = bdrv_create(bdrv_qcow, s->qcow_filename, options); > + if (ret < 0) { > + return ret; > + } (1) This still seems to leak "s->qcow_filename". Maybe that's not an actual leak (the reference is not lost), but the error handler just a little bit higher up frees "s->qcow_filename" and sets it to NULL if get_tmp_filename() fails. If this remark is justified then it could apply to the other error branches. (2) vvfat_open() calls enable_write_target() but doesn't propagate its retval, any error results in -EIO. Would that be worth fixing as well? > > s->qcow = bdrv_new(""); > - if (s->qcow == NULL) { > - return -1; > - } > > ret = bdrv_open(s->qcow, s->qcow_filename, NULL, > BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, bdrv_qcow); > if (ret < 0) { > - return ret; > + bdrv_delete(s->qcow); > + return ret; > } > > #ifndef _WIN32 > Thanks Laszlo