From 0e4d821fb2c6b3b975afa16399fefb032274e9aa Mon Sep 17 00:00:00 2001
From: Markus Armbruster <armbru@redhat.com>
Date: Wed, 31 Mar 2010 13:24:21 -0300
Subject: [PATCH 06/66] qdev: Free opts on failed do_device_add

RH-Author: Markus Armbruster <armbru@redhat.com>
Message-id: <1270041921-28969-7-git-send-email-armbru@redhat.com>
Patchwork-id: 8245
O-Subject: [PATCH 06/66] qdev: Free opts on failed do_device_add
Bugzilla: 579470
RH-Acked-by: Juan Quintela <quintela@redhat.com>
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
RH-Acked-by: Luiz Capitulino <lcapitulino@redhat.com>

From: Kevin Wolf <kwolf@redhat.com>

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.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
(cherry picked from commit 0f853a386739b22e541e6e65ed60a0cb37713340)
---
 hw/qdev.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/qdev.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/hw/qdev.c b/hw/qdev.c
index e4776c7..b634890 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -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)
-- 
1.7.0.3

