From f01a34f04c70cbe9aa6d2ed5577ba70d2ec27d2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Tue, 2 Apr 2019 23:59:38 +0200 Subject: [PATCH] virJSONValueToString: bail out early on error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now that we do not need to cater to YAJL 1, move the check for the return value of yajl_gen_alloc earlier, so that we can assume it was successful in later code. Signed-off-by: Ján Tomko Reviewed-by: Daniel P. Berrangé --- src/util/virjson.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/util/virjson.c b/src/util/virjson.c index 857ee23951..bb4052ba81 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -1941,16 +1941,14 @@ virJSONValueToBuffer(virJSONValuePtr object, VIR_DEBUG("object=%p", object); g = yajl_gen_alloc(NULL); - if (g) { - yajl_gen_config(g, yajl_gen_beautify, pretty ? 1 : 0); - yajl_gen_config(g, yajl_gen_indent_string, pretty ? " " : " "); - yajl_gen_config(g, yajl_gen_validate_utf8, 1); - } if (!g) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to create JSON formatter")); goto cleanup; } + yajl_gen_config(g, yajl_gen_beautify, pretty ? 1 : 0); + yajl_gen_config(g, yajl_gen_indent_string, pretty ? " " : " "); + yajl_gen_config(g, yajl_gen_validate_utf8, 1); if (virJSONValueToStringOne(object, g) < 0) { virReportOOMError();