Use automatic memory clearing to simplify the control flow. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/qemu/qemu_monitor_json.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) 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; } -- 2.31.1