diff mbox

[2/2] vl: call visit_end_struct() in the error path

Message ID 9c5f3c9b11f49b89d5202b4027a36ff1a34e038e.1408093440.git.hutao@cn.fujitsu.com
State New
Headers show

Commit Message

Hu Tao Aug. 15, 2014, 10:14 a.m. UTC
In the error path we should also call visit_end_struct(), otherwise we
will have memory leak.

Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
---
 vl.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
diff mbox

Patch

diff --git a/vl.c b/vl.c
index 6011aff..738ef45 100644
--- a/vl.c
+++ b/vl.c
@@ -2876,6 +2876,7 @@  static int object_create(QemuOpts *opts, void *opaque)
     char *type = NULL;
     char *id = NULL;
     void *dummy = NULL;
+    bool del_id_on_error = false;
     OptsVisitor *ov;
     QDict *pdict;
 
@@ -2890,21 +2891,21 @@  static int object_create(QemuOpts *opts, void *opaque)
     qdict_del(pdict, "qom-type");
     visit_type_str(opts_get_visitor(ov), &type, "qom-type", &err);
     if (err) {
-        goto out;
+        goto out_struct;
     }
 
     qdict_del(pdict, "id");
     visit_type_str(opts_get_visitor(ov), &id, "id", &err);
     if (err) {
-        goto out;
+        goto out_struct;
     }
 
     object_add(type, id, pdict, opts_get_visitor(ov), &err);
-    if (err) {
-        goto out;
-    }
+    del_id_on_error = true;
+
+out_struct:
     visit_end_struct(opts_get_visitor(ov), &err);
-    if (err) {
+    if (err && del_id_on_error) {
         qmp_object_del(id, NULL);
     }