From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43795) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJT81-0005Ox-7z for qemu-devel@nongnu.org; Mon, 18 Aug 2014 16:02:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XJT7u-0003k5-V1 for qemu-devel@nongnu.org; Mon, 18 Aug 2014 16:02:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:24329) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJT7u-0003k1-NY for qemu-devel@nongnu.org; Mon, 18 Aug 2014 16:01:58 -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 s7IK1vvX027964 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 18 Aug 2014 16:01:58 -0400 Message-ID: <53F25BB2.7050303@redhat.com> Date: Mon, 18 Aug 2014 22:01:54 +0200 From: Max Reitz MIME-Version: 1.0 References: <1408392029-29531-1-git-send-email-mreitz@redhat.com> <1408392029-29531-3-git-send-email-mreitz@redhat.com> In-Reply-To: <1408392029-29531-3-git-send-email-mreitz@redhat.com> Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 2/4] qcow2: Use g_try_new0() for cache array List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi On 18.08.2014 22:00, Max Reitz wrote: > With a variable cache size, the number given to qcow2_cache_create() may > be huge. Therefore, use g_try_new0(). > > While at it, use g_new0() instead of g_malloc0() for allocating the > Qcow2Cache object. > > Signed-off-by: Max Reitz > --- > block/qcow2-cache.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c > index fe0615a..6eabfaa 100644 > --- a/block/qcow2-cache.c > +++ b/block/qcow2-cache.c > @@ -48,9 +48,12 @@ Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables) > Qcow2Cache *c; > int i; > > - c = g_malloc0(sizeof(*c)); > + c = g_new0(Qcow2Cache, 1); > c->size = num_tables; > - c->entries = g_new0(Qcow2CachedTable, num_tables); > + c->entries = g_try_new0(Qcow2CachedTable, num_tables); > + if (!c->entries) { > + goto fail; > + } Self-NACK: The fail path needs to acknowledge that c->entries may be NULL. Max