[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 11/20] qcow2: Handle failure for potentially lar
From: |
Stefan Hajnoczi |
Subject: |
Re: [Qemu-devel] [PATCH 11/20] qcow2: Handle failure for potentially large allocations |
Date: |
Thu, 22 May 2014 18:07:44 +0200 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
On Wed, May 21, 2014 at 06:28:09PM +0200, Kevin Wolf wrote:
> diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
> index 8ecbb5b..465ef24 100644
> --- a/block/qcow2-cache.c
> +++ b/block/qcow2-cache.c
> @@ -53,10 +53,20 @@ Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int
> num_tables)
> c->entries = g_malloc0(sizeof(*c->entries) * num_tables);
>
> for (i = 0; i < c->size; i++) {
> - c->entries[i].table = qemu_blockalign(bs, s->cluster_size);
> + c->entries[i].table = qemu_try_blockalign(bs, s->cluster_size);
> + if (c->entries[i].table == NULL) {
> + goto fail;
> + }
> }
>
> return c;
> +
> +fail:
> + for (i = 0; i < c->size; i++) {
> + g_free(c->entries[i].table);
qemu_blockalign() must be paired with qemu_vfree().
Come to think of it, in the patches where you converted malloc to
blockalign, please check that the buffer is vfreed.
> diff --git a/block/qcow2.c b/block/qcow2.c
> index a4b97e8..1efdd17 100644
> --- a/block/qcow2.c
> +++ b/block/qcow2.c
> @@ -676,8 +676,13 @@ static int qcow2_open(BlockDriverState *bs, QDict
> *options, int flags,
>
>
> if (s->l1_size > 0) {
> - s->l1_table = g_malloc0(
> + s->l1_table = qemu_try_blockalign(bs->file,
Is blockalign used consistently for s->l1_table? Or places in this
patch have l1_table = g_try_malloc0(). We need to be careful because of
g_free() vs qemu_vfree().
- [Qemu-devel] [PATCH 07/20] iscsi: Handle failure for potentially large allocations, (continued)
- [Qemu-devel] [PATCH 07/20] iscsi: Handle failure for potentially large allocations, Kevin Wolf, 2014/05/21
- [Qemu-devel] [PATCH 09/20] parallels: Handle failure for potentially large allocations, Kevin Wolf, 2014/05/21
- [Qemu-devel] [PATCH 08/20] nfs: Handle failure for potentially large allocations, Kevin Wolf, 2014/05/21
- [Qemu-devel] [PATCH 10/20] qcow1: Handle failure for potentially large allocations, Kevin Wolf, 2014/05/21
- [Qemu-devel] [PATCH 11/20] qcow2: Handle failure for potentially large allocations, Kevin Wolf, 2014/05/21
- Re: [Qemu-devel] [PATCH 11/20] qcow2: Handle failure for potentially large allocations,
Stefan Hajnoczi <=
- [Qemu-devel] [PATCH 12/20] qed: Handle failure for potentially large allocations, Kevin Wolf, 2014/05/21
- [Qemu-devel] [PATCH 13/20] raw-posix: Handle failure for potentially large allocations, Kevin Wolf, 2014/05/21
- [Qemu-devel] [PATCH 14/20] raw-win32: Handle failure for potentially large allocations, Kevin Wolf, 2014/05/21
- [Qemu-devel] [PATCH 15/20] rbd: Handle failure for potentially large allocations, Kevin Wolf, 2014/05/21
- [Qemu-devel] [PATCH 17/20] vhdx: Handle failure for potentially large allocations, Kevin Wolf, 2014/05/21