qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 16/16] qdev-monitor: Avoid aborting on out-of-memory


From: Andreas Färber
Subject: [Qemu-devel] [PATCH 16/16] qdev-monitor: Avoid aborting on out-of-memory in qdev_device_add()
Date: Sat, 24 Aug 2013 02:00:36 +0200

Use g_try_malloc0() and object_initialize() instead of object_new() to
try letting large hot-add attempts fail without killing a running guest.
This requires obtaining the allocation size with type_get_instance_size().

Aborts can still occur whenever devices use object_new() to create child
devices rather than using object_initialize() on embedded structs. When
allocating dynamic properties fails, chances are there's not enough
memory left to emit Errors either.

Signed-off-by: Andreas Färber <address@hidden>
---
 qdev-monitor.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/qdev-monitor.c b/qdev-monitor.c
index 51bfec0..c5f504f 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -447,6 +447,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
     ObjectClass *oc;
     DeviceClass *dc;
     const char *driver, *path, *id;
+    size_t size;
     DeviceState *qdev;
     BusState *bus = NULL;
 
@@ -500,7 +501,12 @@ DeviceState *qdev_device_add(QemuOpts *opts)
     }
 
     /* create device, set properties */
-    qdev = DEVICE(object_new(driver));
+    size = type_get_instance_size(driver);
+    qdev = g_try_malloc0(size);
+    if (qdev == NULL) {
+        return NULL;
+    }
+    object_initialize(qdev, size, driver);
 
     if (bus) {
         qdev_set_parent_bus(qdev, bus);
-- 
1.8.1.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]