[PATCH 30/33] util: json: Report non-OOM error on yajl failure

Peter Krempa pkrempa at redhat.com
Wed Feb 24 16:17:05 UTC 2021


The yajl library returns a wide range of error codes so reporting OOM on
any failure is wrong. In case the error was really based by memory issue
the error reporting will probably cause an abort anyways. Change the
error message so that we know that it happened in JSON at least.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/util/virjson.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/util/virjson.c b/src/util/virjson.c
index e74b9fca4f..f2a6024db6 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -1943,12 +1943,14 @@ virJSONValueToBuffer(virJSONValuePtr object,
     yajl_gen_config(g, yajl_gen_validate_utf8, 1);

     if (virJSONValueToStringOne(object, g) < 0) {
-        virReportOOMError();
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("failed to convert virJSONValue to yajl data"));
         goto cleanup;
     }

     if (yajl_gen_get_buf(g, &str, &len) != yajl_gen_status_ok) {
-        virReportOOMError();
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                      _("failed to format JSON"));
         goto cleanup;
     }

-- 
2.29.2




More information about the libvir-list mailing list