]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: use virJSONValueObjectGetStringArray
authorMarc-André Lureau <marcandre.lureau@redhat.com>
Fri, 20 Nov 2020 18:09:44 +0000 (22:09 +0400)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 1 Dec 2020 10:23:39 +0000 (11:23 +0100)
There might be more potential users around, I haven't looked thoroughly.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Tested-by: Han Han <hhan@redhat.com>
src/qemu/qemu_monitor_json.c

index 723bdb4426b69631bd74365d6803b95ec38a42a9..e7aa6b6ffdd5ce074477f3148f49c57d316993cf 100644 (file)
@@ -7533,10 +7533,6 @@ qemuMonitorJSONGetStringArray(qemuMonitorPtr mon, const char *qmpCmd,
     int ret = -1;
     virJSONValuePtr cmd;
     virJSONValuePtr reply = NULL;
-    virJSONValuePtr data;
-    char **list = NULL;
-    size_t n = 0;
-    size_t i;
 
     *array = NULL;
 
@@ -7554,32 +7550,12 @@ qemuMonitorJSONGetStringArray(qemuMonitorPtr mon, const char *qmpCmd,
     if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
         goto cleanup;
 
-    data = virJSONValueObjectGetArray(reply, "return");
-    n = virJSONValueArraySize(data);
-
-    /* null-terminated list */
-    list = g_new0(char *, n + 1);
-
-    for (i = 0; i < n; i++) {
-        virJSONValuePtr child = virJSONValueArrayGet(data, i);
-        const char *tmp;
-
-        if (!(tmp = virJSONValueGetString(child))) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("%s array element does not contain data"),
-                           qmpCmd);
-            goto cleanup;
-        }
-
-        list[i] = g_strdup(tmp);
-    }
+    if (!(*array = virJSONValueObjectGetStringArray(reply, "return")))
+        goto cleanup;
 
-    ret = n;
-    *array = list;
-    list = NULL;
+    ret = g_strv_length(*array);
 
  cleanup:
-    g_strfreev(list);
     virJSONValueFree(cmd);
     virJSONValueFree(reply);
     return ret;