From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46980) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgE3y-0001W3-4l for qemu-devel@nongnu.org; Mon, 20 Oct 2014 10:36:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XgE3p-0005qX-VF for qemu-devel@nongnu.org; Mon, 20 Oct 2014 10:35:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32885) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgE3p-0005qO-Mf for qemu-devel@nongnu.org; Mon, 20 Oct 2014 10:35:49 -0400 From: Max Reitz Date: Mon, 20 Oct 2014 16:35:27 +0200 Message-Id: <1413815733-22829-6-git-send-email-mreitz@redhat.com> In-Reply-To: <1413815733-22829-1-git-send-email-mreitz@redhat.com> References: <1413815733-22829-1-git-send-email-mreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v6 05/11] qcow2: Reuse refcount table in calculate_refcounts() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , =?UTF-8?q?Beno=C3=AEt=20Canet?= , Stefan Hajnoczi , Max Reitz We will later call calculate_refcounts multiple times, so reuse the refcount table if possible. Signed-off-by: Max Reitz Reviewed-by: Beno=C3=AEt Canet --- block/qcow2-refcount.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 42de4ab..55a539f 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1623,10 +1623,12 @@ static int calculate_refcounts(BlockDriverState *= bs, BdrvCheckResult *res, QCowSnapshot *sn; int ret; =20 - *refcount_table =3D g_try_new0(uint16_t, *nb_clusters); - if (*nb_clusters && *refcount_table =3D=3D NULL) { - res->check_errors++; - return -ENOMEM; + if (!*refcount_table) { + *refcount_table =3D g_try_new0(uint16_t, *nb_clusters); + if (*nb_clusters && *refcount_table =3D=3D NULL) { + res->check_errors++; + return -ENOMEM; + } } =20 /* header */ @@ -1733,7 +1735,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, Bdr= vCheckResult *res, { BDRVQcowState *s =3D bs->opaque; int64_t size, highest_cluster, nb_clusters; - uint16_t *refcount_table; + uint16_t *refcount_table =3D NULL; int ret; =20 size =3D bdrv_getlength(bs->file); --=20 2.1.2