From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52421) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wrqgd-0003tK-IQ for qemu-devel@nongnu.org; Tue, 03 Jun 2014 11:31:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WrqgY-0006Od-GU for qemu-devel@nongnu.org; Tue, 03 Jun 2014 11:31:39 -0400 Received: from lputeaux-656-01-25-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:38742 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrqgY-0006OV-Az for qemu-devel@nongnu.org; Tue, 03 Jun 2014 11:31:34 -0400 Date: Tue, 3 Jun 2014 17:31:32 +0200 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20140603153132.GH21314@irqsave.net> References: <1401801062-9154-1-git-send-email-kwolf@redhat.com> <1401801062-9154-19-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1401801062-9154-19-git-send-email-kwolf@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3 18/21] vmdk: Handle failure for potentially large allocations List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: benoit.canet@irqsave.net, mreitz@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, armbru@redhat.com The Tuesday 03 Jun 2014 =E0 15:10:59 (+0200), Kevin Wolf wrote : > Some code in the block layer makes potentially huge allocations. Failur= e > is not completely unexpected there, so avoid aborting qemu and handle > out-of-memory situations gracefully. >=20 > This patch addresses the allocations in the vmdk block driver. >=20 > Signed-off-by: Kevin Wolf > Reviewed-by: Stefan Hajnoczi > --- > block/vmdk.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) >=20 > diff --git a/block/vmdk.c b/block/vmdk.c > index 2b38f61..fd81b1f 100644 > --- a/block/vmdk.c > +++ b/block/vmdk.c > @@ -448,7 +448,11 @@ static int vmdk_init_tables(BlockDriverState *bs, = VmdkExtent *extent, > =20 > /* read the L1 table */ > l1_size =3D extent->l1_size * sizeof(uint32_t); > - extent->l1_table =3D g_malloc(l1_size); > + extent->l1_table =3D g_try_malloc(l1_size); > + if (l1_size && extent->l1_table =3D=3D NULL) { > + return -ENOMEM; > + } > + > ret =3D bdrv_pread(extent->file, > extent->l1_table_offset, > extent->l1_table, > @@ -464,7 +468,11 @@ static int vmdk_init_tables(BlockDriverState *bs, = VmdkExtent *extent, > } > =20 > if (extent->l1_backup_table_offset) { > - extent->l1_backup_table =3D g_malloc(l1_size); > + extent->l1_backup_table =3D g_try_malloc(l1_size); > + if (l1_size && extent->l1_backup_table =3D=3D NULL) { > + ret =3D -ENOMEM; > + goto fail_l1; > + } > ret =3D bdrv_pread(extent->file, > extent->l1_backup_table_offset, > extent->l1_backup_table, > --=20 > 1.8.3.1 >=20 >=20 Reviewed-by: Benoit Canet