diff mbox

[v5,02/15] qemu-img: Don't leak errors when outputting JSON

Message ID 1465490926-28625-3-git-send-email-eblake@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Eric Blake June 9, 2016, 4:48 p.m. UTC
If our JSON output ever encounters an error, we would just silently
leak the error object.  Instead, assert that our usage won't fail.

Signed-off-by: Eric Blake <eblake@redhat.com>

---
v5: commit message wording tweak
v4: new patch (split out from v3 14/18)
---
 qemu-img.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
diff mbox

Patch

diff --git a/qemu-img.c b/qemu-img.c
index 251386b..c4a8647 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -483,12 +483,11 @@  fail:

 static void dump_json_image_check(ImageCheck *check, bool quiet)
 {
-    Error *local_err = NULL;
     QString *str;
     QmpOutputVisitor *ov = qmp_output_visitor_new();
     QObject *obj;
     visit_type_ImageCheck(qmp_output_get_visitor(ov), NULL, &check,
-                          &local_err);
+                          &error_abort);
     obj = qmp_output_get_qobject(ov);
     str = qobject_to_json_pretty(obj);
     assert(str != NULL);
@@ -2174,12 +2173,11 @@  static void dump_snapshots(BlockDriverState *bs)

 static void dump_json_image_info_list(ImageInfoList *list)
 {
-    Error *local_err = NULL;
     QString *str;
     QmpOutputVisitor *ov = qmp_output_visitor_new();
     QObject *obj;
     visit_type_ImageInfoList(qmp_output_get_visitor(ov), NULL, &list,
-                             &local_err);
+                             &error_abort);
     obj = qmp_output_get_qobject(ov);
     str = qobject_to_json_pretty(obj);
     assert(str != NULL);
@@ -2191,11 +2189,11 @@  static void dump_json_image_info_list(ImageInfoList *list)

 static void dump_json_image_info(ImageInfo *info)
 {
-    Error *local_err = NULL;
     QString *str;
     QmpOutputVisitor *ov = qmp_output_visitor_new();
     QObject *obj;
-    visit_type_ImageInfo(qmp_output_get_visitor(ov), NULL, &info, &local_err);
+    visit_type_ImageInfo(qmp_output_get_visitor(ov), NULL, &info,
+                         &error_abort);
     obj = qmp_output_get_qobject(ov);
     str = qobject_to_json_pretty(obj);
     assert(str != NULL);