Skip to contentSkip to conversation

qdev: Free opts on failed do_device_add

PATCH Applied Kevin Wolf 3 participants 3 messages Feb 16, 2010 – Feb 19, 2010

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 qdev: Free opts on failed do_device_add

If the device can't be created, don't leak the QemuOpts and release the id of the device that should have been added by the failed device_add.

---
 hw/qdev.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
hw/qdev.c +5 -2
index 539b5a2..d0052d4 100644
@@ -749,8 +749,11 @@ void do_device_add(Monitor *mon, const QDict *qdict)
 
     opts = qemu_opts_parse(&qemu_device_opts,
                            qdict_get_str(qdict, "config"), "driver");
-    if (opts && !qdev_device_help(opts))
-        qdev_device_add(opts);
+    if (opts) {
+        if (qdev_device_help(opts) || qdev_device_add(opts) == NULL) {
+            qemu_opts_del(opts);
+        }
+    }
 }
 
 void do_device_del(Monitor *mon, const QDict *qdict)
Signature · 1 line
1.6.6
Acked-by on v1 1/1
#1 lore raw
Quoted 2 lines · Kevin Wolf

If the device can't be created, don't leak the QemuOpts and release the id of the device that should have been added by the failed device_add.

cheers,
Gerd

#2 lore raw
In reply to Kevin Wolf
Quoted 5 lines · Kevin Wolf

If the device can't be created, don't leak the QemuOpts and release the id of the device that should have been added by the failed device_add.

Applied. Thanks.

Regards,

Anthony Liguori

Quoted 23 lines
---
  hw/qdev.c |    7 +++++--
  1 files changed, 5 insertions(+), 2 deletions(-)
hw/qdev.c +5 -2
index 539b5a2..d0052d4 100644
@@ -749,8 +749,11 @@ void do_device_add(Monitor *mon, const QDict *qdict)
 
      opts = qemu_opts_parse(&qemu_device_opts,
                             qdict_get_str(qdict, "config"), "driver");
-    if (opts&&  !qdev_device_help(opts))
-        qdev_device_add(opts);
+    if (opts) {
+        if (qdev_device_help(opts) || qdev_device_add(opts) == NULL) {
+            qemu_opts_del(opts);
+        }
+    }
  }
 
  void do_device_del(Monitor *mon, const QDict *qdict)