From d195325b05199038b5907fa791729425b9720d21 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 17 Jul 2012 16:17:04 +0200 Subject: qapi: fix error propagation Don't overwrite / leak previously set errors. Make traversal cope with missing mandatory sub-structs. Don't try to end a container that could not be started. v1->v2: - unchanged v2->v3: - instead of examining, assert that we never overwrite errors with error_set() - allow visitors to set a NULL struct pointer successfully, so traversal of incomplete objects can continue - check for a NULL "obj" before accessing "(*obj)->has_XXX" (this is not a typo, "obj != NULL" implies "*obj != NULL" here) - fix start_struct / end_struct balance for unions as well Signed-off-by: Paolo Bonzini Signed-off-by: Laszlo Ersek Signed-off-by: Stefan Hajnoczi --- error.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'error.c') diff --git a/error.c b/error.c index a52b7710d2..58f55a012e 100644 --- a/error.c +++ b/error.c @@ -32,6 +32,7 @@ void error_set(Error **errp, const char *fmt, ...) if (errp == NULL) { return; } + assert(*errp == NULL); err = g_malloc0(sizeof(*err)); @@ -132,7 +133,7 @@ bool error_is_type(Error *err, const char *fmt) void error_propagate(Error **dst_err, Error *local_err) { - if (dst_err) { + if (dst_err && !*dst_err) { *dst_err = local_err; } else if (local_err) { error_free(local_err); -- cgit v1.2.3