[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 56/62] vmdk: Handle failure for potentially large all
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 56/62] vmdk: Handle failure for potentially large allocations |
Date: |
Fri, 8 Aug 2014 19:39:57 +0200 |
Some code in the block layer makes potentially huge allocations. Failure
is not completely unexpected there, so avoid aborting qemu and handle
out-of-memory situations gracefully.
This patch addresses the allocations in the vmdk block driver.
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
Reviewed-by: Benoit Canet <address@hidden>
---
block/vmdk.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/block/vmdk.c b/block/vmdk.c
index 3700a11..01412a8 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -456,7 +456,11 @@ static int vmdk_init_tables(BlockDriverState *bs,
VmdkExtent *extent,
/* read the L1 table */
l1_size = extent->l1_size * sizeof(uint32_t);
- extent->l1_table = g_malloc(l1_size);
+ extent->l1_table = g_try_malloc(l1_size);
+ if (l1_size && extent->l1_table == NULL) {
+ return -ENOMEM;
+ }
+
ret = bdrv_pread(extent->file,
extent->l1_table_offset,
extent->l1_table,
@@ -472,7 +476,11 @@ static int vmdk_init_tables(BlockDriverState *bs,
VmdkExtent *extent,
}
if (extent->l1_backup_table_offset) {
- extent->l1_backup_table = g_malloc(l1_size);
+ extent->l1_backup_table = g_try_malloc(l1_size);
+ if (l1_size && extent->l1_backup_table == NULL) {
+ ret = -ENOMEM;
+ goto fail_l1;
+ }
ret = bdrv_pread(extent->file,
extent->l1_backup_table_offset,
extent->l1_backup_table,
--
1.8.3.1
- [Qemu-devel] [PULL 48/62] qcow1: Handle failure for potentially large allocations, (continued)
- [Qemu-devel] [PULL 48/62] qcow1: Handle failure for potentially large allocations, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 51/62] raw-posix: Handle failure for potentially large allocations, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 52/62] raw-win32: Handle failure for potentially large allocations, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 49/62] qcow2: Handle failure for potentially large allocations, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 54/62] vdi: Handle failure for potentially large allocations, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 53/62] rbd: Handle failure for potentially large allocations, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 55/62] vhdx: Handle failure for potentially large allocations, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 57/62] vpc: Handle failure for potentially large allocations, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 58/62] mirror: Handle failure for potentially large allocations, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 59/62] qcow2: Return useful error code in refcount_init(), Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 56/62] vmdk: Handle failure for potentially large allocations,
Kevin Wolf <=
- [Qemu-devel] [PULL 60/62] qcow2: Catch !*host_offset for data allocation, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 61/62] iotests: Add test for image header overlap, Kevin Wolf, 2014/08/08
- [Qemu-devel] [PULL 62/62] block: Catch !bs->drv in bdrv_check(), Kevin Wolf, 2014/08/08
- Re: [Qemu-devel] [PULL 00/62] Block patches, Peter Maydell, 2014/08/15