From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40347) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UzLun-0005s2-1A for qemu-devel@nongnu.org; Wed, 17 Jul 2013 03:12:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UzLuj-0003gP-Oz for qemu-devel@nongnu.org; Wed, 17 Jul 2013 03:12:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31459) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UzLuj-0003g6-HL for qemu-devel@nongnu.org; Wed, 17 Jul 2013 03:12:41 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r6H7CdF3006610 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 17 Jul 2013 03:12:39 -0400 From: Fam Zheng Date: Wed, 17 Jul 2013 15:12:25 +0800 Message-Id: <1374045145-2278-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH] block: fix vvfat s->qcow leak on error List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, Fam Zheng , stefanha@redhat.com 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; + } 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 -- 1.8.3.2