From: Peter Krempa Date: Mon, 14 Jun 2021 14:20:50 +0000 (+0200) Subject: qemuMonitorJSONGetObjectTypes: Refactor cleanup X-Git-Tag: v7.5.0-rc1~81 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed4c75c4daf4c629f54343870f953c5324ba8c4d;p=thirdparty%2Flibvirt.git qemuMonitorJSONGetObjectTypes: Refactor cleanup Use automatic memory clearing to simplify the control flow. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index c25e282d51..74e06e7604 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -6293,14 +6293,14 @@ int qemuMonitorJSONGetKVMState(qemuMonitor *mon, } -int qemuMonitorJSONGetObjectTypes(qemuMonitor *mon, - char ***types) +int +qemuMonitorJSONGetObjectTypes(qemuMonitor *mon, + char ***types) { - int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; virJSONValue *data; - char **typelist = NULL; + g_auto(GStrv) typelist = NULL; size_t n = 0; size_t i; @@ -6310,10 +6310,10 @@ int qemuMonitorJSONGetObjectTypes(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) - goto cleanup; + return -1; data = virJSONValueObjectGetArray(reply, "return"); n = virJSONValueArraySize(data); @@ -6328,20 +6328,14 @@ int qemuMonitorJSONGetObjectTypes(qemuMonitor *mon, if (!(tmp = virJSONValueObjectGetString(child, "name"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("qom-list-types reply data was missing 'name'")); - goto cleanup; + return -1; } typelist[i] = g_strdup(tmp); } - ret = n; *types = g_steal_pointer(&typelist); - - cleanup: - g_strfreev(typelist); - virJSONValueFree(cmd); - virJSONValueFree(reply); - return ret; + return n; }