[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 05/55] qcow2: Use g_try_realloc() in qcow2_expand_zer
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 05/55] qcow2: Use g_try_realloc() in qcow2_expand_zero_clusters() |
Date: |
Tue, 13 Feb 2018 18:04:39 +0100 |
From: Alberto Garcia <address@hidden>
g_realloc() aborts the program if it fails to allocate the required
amount of memory. We want to detect that scenario and return an error
instead, so let's use g_try_realloc().
Signed-off-by: Alberto Garcia <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/qcow2-cluster.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 3a979bcd82..f077cd3ac5 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -2070,7 +2070,15 @@ int qcow2_expand_zero_clusters(BlockDriverState *bs,
int l1_sectors = DIV_ROUND_UP(s->snapshots[i].l1_size *
sizeof(uint64_t), BDRV_SECTOR_SIZE);
- l1_table = g_realloc(l1_table, l1_sectors * BDRV_SECTOR_SIZE);
+ uint64_t *new_l1_table =
+ g_try_realloc(l1_table, l1_sectors * BDRV_SECTOR_SIZE);
+
+ if (!new_l1_table) {
+ ret = -ENOMEM;
+ goto fail;
+ }
+
+ l1_table = new_l1_table;
ret = bdrv_read(bs->file,
s->snapshots[i].l1_table_offset / BDRV_SECTOR_SIZE,
--
2.13.6
- [Qemu-block] [PULL 00/55] Block layer patches, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 01/55] iotests: Fix CID for VMDK afl image, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 03/55] qemu-img: Document --force-share / -U, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 02/55] qemu-img.texi: Clean up parameter list, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 09/55] gluster: Move glfs_close() to create's clean-up, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 11/55] gluster: Query current size in do_truncate(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 04/55] docs: Document share-rw property more thoroughly, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 10/55] gluster: Pull truncation from qemu_gluster_create, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 06/55] block: early check for blockers on drive-mirror, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 05/55] qcow2: Use g_try_realloc() in qcow2_expand_zero_clusters(),
Kevin Wolf <=
- [Qemu-block] [PULL 08/55] qemu-io: fix EOF Ctrl-D handling in qemu-io readline code, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 07/55] iotests: Use virtio-blk in 155, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 15/55] sheepdog: Allow fully preallocated truncation, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 13/55] sheepdog: Make sd_prealloc() take a BDS, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 17/55] qcow2: Fix documentation of get_cluster_table(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 14/55] sheepdog: Pass old and new size to sd_prealloc(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 12/55] gluster: Add preallocated truncation, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 18/55] qcow2: Add table size field to Qcow2Cache, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 19/55] qcow2: Remove BDS parameter from qcow2_cache_get_table_addr(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 20/55] qcow2: Remove BDS parameter from qcow2_cache_get_table_idx(), Kevin Wolf, 2018/02/13