Received: from eggs.gnu.org ([2001:4830:134:3::10]:41376) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aP9QF-0003Ua-Pi for qemu-devel@nongnu.org; Fri, 29 Jan 2016 08:49:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aP9QE-0001ID-4W for qemu-devel@nongnu.org; Fri, 29 Jan 2016 08:49:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40462) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aP9QD-0001Hz-Vv for qemu-devel@nongnu.org; Fri, 29 Jan 2016 08:49:10 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 90195743 for ; Fri, 29 Jan 2016 13:49:09 +0000 (UTC) From: Eric Blake Date: Fri, 29 Jan 2016 06:48:44 -0700 Message-Id: <1454075341-13658-9-git-send-email-eblake@redhat.com> In-Reply-To: <1454075341-13658-1-git-send-email-eblake@redhat.com> References: <1454075341-13658-1-git-send-email-eblake@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v10 08/25] vl: Ensure qapi visitor properly ends struct visit List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: marcandre.lureau@redhat.com, armbru@redhat.com, Paolo Bonzini 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 Reviewed-by: Marc-Andr=C3=A9 Lureau --- v10: resplit 4/37 and 5/37 by action rather than file, retain R-b. v9: no change v8: no change v7: place earlier in series, drop attempts to provide a 'kind' string, drop bogus avoidance of qmp_object_del() on error v6: new patch, split from RFC on v5 7/46 --- vl.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/vl.c b/vl.c index 24d30f2..aaa5403 100644 --- a/vl.c +++ b/vl.c @@ -2822,6 +2822,7 @@ static bool object_create_delayed(const char *type) static int object_create(void *opaque, QemuOpts *opts, Error **errp) { Error *err =3D NULL; + Error *err_end =3D NULL; char *type =3D NULL; char *id =3D NULL; OptsVisitor *ov; @@ -2844,23 +2845,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); --=20 2.5.0