From patchwork Thu Dec 9 11:10:00 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 74942 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9CB11B70EC for ; Fri, 10 Dec 2010 03:54:09 +1100 (EST) Received: from localhost ([127.0.0.1]:37120 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQjkd-0006cF-OK for incoming@patchwork.ozlabs.org; Thu, 09 Dec 2010 11:53:52 -0500 Received: from [140.186.70.92] (port=44589 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQeN9-0006HL-G4 for qemu-devel@nongnu.org; Thu, 09 Dec 2010 06:09:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PQeN5-0000G9-S5 for qemu-devel@nongnu.org; Thu, 09 Dec 2010 06:09:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45443) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PQeN5-0000Ft-Ir for qemu-devel@nongnu.org; Thu, 09 Dec 2010 06:09:11 -0500 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.13.8/8.13.8) with ESMTP id oB9B9AsE006071 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 9 Dec 2010 06:09:10 -0500 Received: from dhcp-5-188.str.redhat.com (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oB9B91nq014178; Thu, 9 Dec 2010 06:09:09 -0500 From: Kevin Wolf To: anthony@codemonkey.ws Date: Thu, 9 Dec 2010 12:10:00 +0100 Message-Id: <1291893010-29223-5-git-send-email-kwolf@redhat.com> In-Reply-To: <1291893010-29223-1-git-send-email-kwolf@redhat.com> References: <1291893010-29223-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 04/14] img_convert(): Only try to free bs[] entries if bs is valid. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Jes Sorensen This allows for jumping to 'out:' consistently for error exit. Signed-off-by: Jes Sorensen Signed-off-by: Kevin Wolf --- qemu-img.c | 13 ++++++++----- 1 files changed, 8 insertions(+), 5 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index eca99c4..aded72d 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -696,7 +696,8 @@ static int img_convert(int argc, char **argv) if (bs_n > 1 && out_baseimg) { error("-B makes no sense when concatenating multiple input images"); - return 1; + ret = -1; + goto out; } bs = qemu_mallocz(bs_n * sizeof(BlockDriverState *)); @@ -974,12 +975,14 @@ out: if (out_bs) { bdrv_delete(out_bs); } - for (bs_i = 0; bs_i < bs_n; bs_i++) { - if (bs[bs_i]) { - bdrv_delete(bs[bs_i]); + if (bs) { + for (bs_i = 0; bs_i < bs_n; bs_i++) { + if (bs[bs_i]) { + bdrv_delete(bs[bs_i]); + } } + qemu_free(bs); } - qemu_free(bs); if (ret) { return 1; }