qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PULL 12/31] vl: Ensure qapi visitor properly ends struct v


From: Markus Armbruster
Subject: [Qemu-devel] [PULL 12/31] vl: Ensure qapi visitor properly ends struct visit
Date: Tue, 9 Feb 2016 12:37:44 +0100

From: Eric Blake <address@hidden>

Guarantee that visit_end_struct() is called if
visit_start_struct() succeeded.  This matches the behavior of
most other uses of visitors, and is a step towards the possibility
of a future patch that adds and enforces some tighter semantics to
the visitor interface (namely, cleanup of the visitor would no
longer have to mop up as many leftovers from an aborted partial
visit).

The change to code here matches the flow of hmp.c:hmp_object_add();
a later patch will then further simplify the cleanup logic of both
places by refactoring visit_end_struct() to not require a second
local error object.

Signed-off-by: Eric Blake <address@hidden>
Reviewed-by: Marc-André Lureau <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Markus Armbruster <address@hidden>
---
 vl.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/vl.c b/vl.c
index 245b2ba..300a609 100644
--- a/vl.c
+++ b/vl.c
@@ -2819,6 +2819,7 @@ static bool object_create_delayed(const char *type)
 static int object_create(void *opaque, QemuOpts *opts, Error **errp)
 {
     Error *err = NULL;
+    Error *err_end = NULL;
     char *type = NULL;
     char *id = NULL;
     OptsVisitor *ov;
@@ -2841,23 +2842,24 @@ static int object_create(void *opaque, QemuOpts *opts, 
Error **errp)
         goto out;
     }
     if (!type_predicate(type)) {
+        visit_end_struct(v, NULL);
         goto out;
     }
 
     qdict_del(pdict, "id");
     visit_type_str(v, &id, "id", &err);
     if (err) {
-        goto out;
+        goto out_end;
     }
 
     object_add(type, id, pdict, v, &err);
-    if (err) {
-        goto out;
-    }
-    visit_end_struct(v, &err);
-    if (err) {
+
+out_end:
+    visit_end_struct(v, &err_end);
+    if (!err && err_end) {
         qmp_object_del(id, NULL);
     }
+    error_propagate(&err, err_end);
 
 out:
     opts_visitor_cleanup(ov);
-- 
2.4.3




reply via email to

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