[PATCH 00/13] qemu_monitor_json: Use g_auto* more

*** BLURB HERE *** Michal Prívozník (13): qemu_monitor_json: Don't check for qemuMonitorNextCommandID() retval qemu_monitor_json: Don't transfer ownership to @msg qemuMonitorJSONHumanCommand: Require @reply_str qemuMonitorJSONGetMigrationStats: Don't clear @stats on failure qemuMonitorJSONQueryRxFilterParse: Set *filter only on success qemu_monitor: Declare and use g_autoptr for qemuMonitorEventPanicInfo qemu_monitor_json: Use g_autoptr() for virCPUData qemu_monitor_json: Use g_autoptr() for qemuMonitorCPUModelInfo qemuMonitorJSONExtractPRManagerInfo: Declare @entry inside the loop qemu_monitor_json: Use g_autoptr() for virJSONValue qemu_monitor_json: Use g_autofree qemu_monitor_json: Drop pointless cleanup labels qemu_monitor_json: Drop pointless error labels src/qemu/qemu_monitor.c | 2 +- src/qemu/qemu_monitor.h | 3 +- src/qemu/qemu_monitor_json.c | 1803 ++++++++++++---------------------- 3 files changed, 641 insertions(+), 1167 deletions(-) -- 2.32.0

The qemuMonitorNextCommandID() function can never fail. There's no need to check for its retval then. Moreover, the temporary variable used to hold the retval can be declared in the inner most block. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_monitor_json.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index a7a980fccd..dcf9186191 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -302,15 +302,14 @@ qemuMonitorJSONCommandWithFd(qemuMonitor *mon, int ret = -1; qemuMonitorMessage msg; g_auto(virBuffer) cmdbuf = VIR_BUFFER_INITIALIZER; - char *id = NULL; *reply = NULL; memset(&msg, 0, sizeof(msg)); if (virJSONValueObjectHasKey(cmd, "execute") == 1) { - if (!(id = qemuMonitorNextCommandID(mon))) - goto cleanup; + g_autofree char *id = qemuMonitorNextCommandID(mon); + if (virJSONValueObjectAppendString(cmd, "id", id) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to append command 'id' string")); @@ -339,7 +338,6 @@ qemuMonitorJSONCommandWithFd(qemuMonitor *mon, } cleanup: - VIR_FREE(id); VIR_FREE(msg.txBuffer); return ret; -- 2.32.0

In qemuMonitorJSONCommandWithFd() given command (represented by virJSONValue struct) is translated to string (represented by virBuffer). The ownership of the string is then transferred to the message which is then sent. The downside of this approach is we have to have an explicit call to free the string from the message. But if the message just "borrowed" the string (which it can safely do because it is just reading from the string) then automatic free of the buffer takes care of freeing the string. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_monitor.c | 2 +- src/qemu/qemu_monitor.h | 2 +- src/qemu/qemu_monitor_json.c | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 81d9087839..908ee0d302 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -420,7 +420,7 @@ static int qemuMonitorIOWrite(qemuMonitor *mon) { int done; - char *buf; + const char *buf; size_t len; /* If no active message, or fully transmitted, the no-op */ diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index f452d0d306..2508e89503 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -39,7 +39,7 @@ typedef struct _qemuMonitorMessage qemuMonitorMessage; struct _qemuMonitorMessage { int txFD; - char *txBuffer; + const char *txBuffer; int txOffset; int txLength; diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index dcf9186191..6d8ccd91e8 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -322,7 +322,7 @@ qemuMonitorJSONCommandWithFd(qemuMonitor *mon, virBufferAddLit(&cmdbuf, "\r\n"); msg.txLength = virBufferUse(&cmdbuf); - msg.txBuffer = virBufferContentAndReset(&cmdbuf); + msg.txBuffer = virBufferCurrentContent(&cmdbuf); msg.txFD = scm_fd; ret = qemuMonitorSend(mon, &msg); @@ -338,8 +338,6 @@ qemuMonitorJSONCommandWithFd(qemuMonitor *mon, } cleanup: - VIR_FREE(msg.txBuffer); - return ret; } -- 2.32.0

All callers of qemuMonitorJSONHumanCommand() pass a non-NULL pointer as @reply_str therefore there's no need to check whether it is NULL. NB, the sister function (qemuMonitorJSONArbitraryCommand()) doesn't check for NULL either. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_monitor_json.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 6d8ccd91e8..7833038a06 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -1470,6 +1470,7 @@ qemuMonitorJSONHumanCommand(qemuMonitor *mon, virJSONValue *cmd = NULL; virJSONValue *reply = NULL; virJSONValue *obj; + const char *data; int ret = -1; cmd = qemuMonitorJSONMakeCommand("human-monitor-command", @@ -1490,13 +1491,8 @@ qemuMonitorJSONHumanCommand(qemuMonitor *mon, goto cleanup; obj = virJSONValueObjectGet(reply, "return"); - - if (reply_str) { - const char *data; - - data = virJSONValueGetString(obj); - *reply_str = g_strdup(NULLSTR_EMPTY(data)); - } + data = virJSONValueGetString(obj); + *reply_str = g_strdup(NULLSTR_EMPTY(data)); ret = 0; -- 2.32.0

In the qemuMonitorJSONGetMigrationStats() there's a code under cleanup label that's clearing returned @stats if the function returns with an error. However, transitively there's just one caller - qemuMigrationAnyFetchStats() - and it doesn't care for this behaviour. Drop the code to simplify the cleanup label. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_monitor_json.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 7833038a06..bcbb4e59ab 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -3542,8 +3542,6 @@ int qemuMonitorJSONGetMigrationStats(qemuMonitor *mon, ret = 0; cleanup: - if (ret < 0) - memset(stats, 0, sizeof(*stats)); virJSONValueFree(cmd); virJSONValueFree(reply); return ret; -- 2.32.0

The qemuMonitorJSONQueryRxFilterParse() function is called to parse the output of 'query-rx-filter' and store results into passed virNetDevRxFilter structure. However, it is doing so in a bit clumsy way - the return pointer is set in all cases (i.e. even in case of error) and thus the cleanup label is more complicated than it needs to be. With a help of g_autoptr() and g_steal_pointer() the return pointer can be set only in case of success - which is what callers expect anyway. The same applies to qemuMonitorJSONQueryRxFilter(). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_monitor_json.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index bcbb4e59ab..26cbb8cedc 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -4035,7 +4035,7 @@ qemuMonitorJSONQueryRxFilterParse(virJSONValue *msg, virJSONValue *element; size_t nTable; size_t i; - virNetDevRxFilter *fil = virNetDevRxFilterNew(); + g_autoptr(virNetDevRxFilter) fil = virNetDevRxFilterNew(); if (!fil) goto cleanup; @@ -4187,13 +4187,9 @@ qemuMonitorJSONQueryRxFilterParse(virJSONValue *msg, } fil->vlan.nTable = nTable; + *filter = g_steal_pointer(&fil); ret = 0; cleanup: - if (ret < 0) { - virNetDevRxFilterFree(fil); - fil = NULL; - } - *filter = fil; return ret; } @@ -4222,10 +4218,6 @@ qemuMonitorJSONQueryRxFilter(qemuMonitor *mon, const char *alias, ret = 0; cleanup: - if (ret < 0) { - virNetDevRxFilterFree(*filter); - *filter = NULL; - } virJSONValueFree(cmd); virJSONValueFree(reply); return ret; -- 2.32.0

Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_monitor.h | 1 + src/qemu/qemu_monitor_json.c | 22 ++++++---------------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 2508e89503..8214c2fd9f 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -194,6 +194,7 @@ struct _qemuMonitorJobInfo { char *qemuMonitorGuestPanicEventInfoFormatMsg(qemuMonitorEventPanicInfo *info); void qemuMonitorEventPanicInfoFree(qemuMonitorEventPanicInfo *info); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuMonitorEventPanicInfo, qemuMonitorEventPanicInfoFree); void qemuMonitorEventRdmaGidStatusFree(qemuMonitorRdmaGidStatus *info); void qemuMonitorMemoryDeviceSizeChangeFree(qemuMonitorMemoryDeviceSizeChange *info); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 26cbb8cedc..655d2a022f 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -605,9 +605,7 @@ static void qemuMonitorJSONHandleResume(qemuMonitor *mon, virJSONValue *data G_G static qemuMonitorEventPanicInfo * qemuMonitorJSONGuestPanicExtractInfoHyperv(virJSONValue *data) { - qemuMonitorEventPanicInfo *ret; - - ret = g_new0(qemuMonitorEventPanicInfo, 1); + g_autoptr(qemuMonitorEventPanicInfo) ret = g_new0(qemuMonitorEventPanicInfo, 1); ret->type = QEMU_MONITOR_EVENT_PANIC_INFO_TYPE_HYPERV; @@ -618,20 +616,16 @@ qemuMonitorJSONGuestPanicExtractInfoHyperv(virJSONValue *data) virJSONValueObjectGetNumberUlong(data, "arg5", &ret->data.hyperv.arg5) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed hyperv panic data")); - goto error; + return NULL; } - return ret; - - error: - qemuMonitorEventPanicInfoFree(ret); - return NULL; + return g_steal_pointer(&ret); } static qemuMonitorEventPanicInfo * qemuMonitorJSONGuestPanicExtractInfoS390(virJSONValue *data) { - qemuMonitorEventPanicInfo *ret; + g_autoptr(qemuMonitorEventPanicInfo) ret = NULL; int core; unsigned long long psw_mask, psw_addr; const char *reason = NULL; @@ -645,7 +639,7 @@ qemuMonitorJSONGuestPanicExtractInfoS390(virJSONValue *data) virJSONValueObjectGetNumberUlong(data, "psw-addr", &psw_addr) < 0 || !(reason = virJSONValueObjectGetString(data, "reason"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed s390 panic data")); - goto error; + return NULL; } ret->data.s390.core = core; @@ -654,11 +648,7 @@ qemuMonitorJSONGuestPanicExtractInfoS390(virJSONValue *data) ret->data.s390.reason = g_strdup(reason); - return ret; - - error: - qemuMonitorEventPanicInfoFree(ret); - return NULL; + return g_steal_pointer(&ret); } static qemuMonitorEventPanicInfo * -- 2.32.0

We have g_autoptr() for virCPUData struct defined already. Let's use it in qemu_monitor_json.c and drop explicit free calls. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_monitor_json.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 655d2a022f..3d89afa6c6 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -7288,7 +7288,7 @@ qemuMonitorJSONParseCPUx86FeatureWord(virJSONValue *data, static virCPUData * qemuMonitorJSONParseCPUx86Features(virJSONValue *data) { - virCPUData *cpudata = NULL; + g_autoptr(virCPUData) cpudata = NULL; virCPUx86DataItem item = { 0 }; size_t i; @@ -7303,10 +7303,9 @@ qemuMonitorJSONParseCPUx86Features(virJSONValue *data) goto error; } - return cpudata; + return g_steal_pointer(&cpudata); error: - virCPUDataFree(cpudata); return NULL; } @@ -7418,8 +7417,8 @@ qemuMonitorJSONGetGuestCPUx86(qemuMonitor *mon, virCPUData **data, virCPUData **disabled) { - virCPUData *cpuEnabled = NULL; - virCPUData *cpuDisabled = NULL; + g_autoptr(virCPUData) cpuEnabled = NULL; + g_autoptr(virCPUData) cpuDisabled = NULL; int rc; if ((rc = qemuMonitorJSONCheckCPUx86(mon)) < 0) @@ -7436,14 +7435,12 @@ qemuMonitorJSONGetGuestCPUx86(qemuMonitor *mon, &cpuDisabled) < 0) goto error; - *data = cpuEnabled; + *data = g_steal_pointer(&cpuEnabled); if (disabled) - *disabled = cpuDisabled; + *disabled = g_steal_pointer(&cpuDisabled); return 0; error: - virCPUDataFree(cpuEnabled); - virCPUDataFree(cpuDisabled); return -1; } @@ -7554,8 +7551,8 @@ qemuMonitorJSONGetGuestCPU(qemuMonitor *mon, virCPUData **enabled, virCPUData **disabled) { - virCPUData *cpuEnabled = NULL; - virCPUData *cpuDisabled = NULL; + g_autoptr(virCPUData) cpuEnabled = NULL; + g_autoptr(virCPUData) cpuDisabled = NULL; int ret = -1; if (!(cpuEnabled = virCPUDataNew(arch)) || @@ -7576,8 +7573,6 @@ qemuMonitorJSONGetGuestCPU(qemuMonitor *mon, ret = 0; cleanup: - virCPUDataFree(cpuEnabled); - virCPUDataFree(cpuDisabled); return ret; } -- 2.32.0

There's one place (specifically qemuMonitorJSONParseCPUModel()) where we can avoid explicit free call for qemuMonitorCPUModelInfo struct. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_monitor_json.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 3d89afa6c6..f59688dfd5 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -5693,7 +5693,7 @@ qemuMonitorJSONParseCPUModel(const char *cpu_name, virJSONValue *cpu_props, qemuMonitorCPUModelInfo **model_info) { - qemuMonitorCPUModelInfo *machine_model = NULL; + g_autoptr(qemuMonitorCPUModelInfo) machine_model = NULL; int ret = -1; machine_model = g_new0(qemuMonitorCPUModelInfo, 1); @@ -5714,7 +5714,6 @@ qemuMonitorJSONParseCPUModel(const char *cpu_name, ret = 0; cleanup: - qemuMonitorCPUModelInfoFree(machine_model); return ret; } -- 2.32.0

The reason why @entry variable in qemuMonitorJSONExtractPRManagerInfo() was declared at the top most level was that the variable is used under the cleanup label. However, if declared using g_autofree then the variable can be declared inside the loop it is used in. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_monitor_json.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index f59688dfd5..f7bc680035 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -8622,7 +8622,6 @@ static int qemuMonitorJSONExtractPRManagerInfo(virJSONValue *reply, GHashTable *info) { - qemuMonitorPRManagerInfo *entry = NULL; virJSONValue *data; int ret = -1; size_t i; @@ -8630,6 +8629,7 @@ qemuMonitorJSONExtractPRManagerInfo(virJSONValue *reply, data = virJSONValueObjectGetArray(reply, "return"); for (i = 0; i < virJSONValueArraySize(data); i++) { + g_autofree qemuMonitorPRManagerInfo *entry = NULL; virJSONValue *prManager = virJSONValueArrayGet(data, i); const char *alias; @@ -8652,7 +8652,6 @@ qemuMonitorJSONExtractPRManagerInfo(virJSONValue *reply, ret = 0; cleanup: - VIR_FREE(entry); return ret; malformed: -- 2.32.0

A lot of explicit free calls can be saved when virJSONValue variables are declared with g_autoptr(). There's one caveat: there was a slight deviation from our usual pattern such that @cmd variable was not initialized to NULL but as the very first step it was assigned a value using qemuMonitorJSONMakeCommand(). While this works in theory it upset my GCC-11.2 (but only when building with -O2). So I had to initialize the variable in such case too. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_monitor_json.c | 623 +++++++++++++---------------------- 1 file changed, 227 insertions(+), 396 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index f7bc680035..1eb0b3b54c 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -216,7 +216,7 @@ qemuMonitorJSONIOProcessLine(qemuMonitor *mon, const char *line, qemuMonitorMessage *msg) { - virJSONValue *obj = NULL; + g_autoptr(virJSONValue) obj = NULL; int ret = -1; VIR_DEBUG("Line [%s]", line); @@ -254,7 +254,6 @@ qemuMonitorJSONIOProcessLine(qemuMonitor *mon, } cleanup: - virJSONValueFree(obj); return ret; } @@ -1457,8 +1456,8 @@ qemuMonitorJSONHumanCommand(qemuMonitor *mon, const char *cmd_str, char **reply_str) { - virJSONValue *cmd = NULL; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; virJSONValue *obj; const char *data; int ret = -1; @@ -1487,8 +1486,6 @@ qemuMonitorJSONHumanCommand(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -1517,14 +1514,15 @@ int qemuMonitorJSONStartCPUs(qemuMonitor *mon) { int ret; - virJSONValue *cmd = qemuMonitorJSONMakeCommand("cont", NULL); - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("cont", NULL); size_t i = 0; int timeout = 3; if (!cmd) return -1; do { + g_autoptr(virJSONValue) reply = NULL; + ret = qemuMonitorJSONCommand(mon, cmd, &reply); if (ret != 0) @@ -1539,13 +1537,9 @@ qemuMonitorJSONStartCPUs(qemuMonitor *mon) if (!qemuMonitorJSONHasError(reply, "MigrationExpected")) break; - virJSONValueFree(reply); - reply = NULL; g_usleep(250000); } while (++i <= timeout); - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -1554,8 +1548,9 @@ int qemuMonitorJSONStopCPUs(qemuMonitor *mon) { int ret = -1; - virJSONValue *cmd = qemuMonitorJSONMakeCommand("stop", NULL); - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("stop", NULL); + g_autoptr(virJSONValue) reply = NULL; + if (!cmd) return -1; @@ -1567,8 +1562,6 @@ qemuMonitorJSONStopCPUs(qemuMonitor *mon) ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -1617,8 +1610,9 @@ qemuMonitorJSONGetStatus(qemuMonitor *mon, int qemuMonitorJSONSystemPowerdown(qemuMonitor *mon) { int ret = -1; - virJSONValue *cmd = qemuMonitorJSONMakeCommand("system_powerdown", NULL); - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("system_powerdown", NULL); + g_autoptr(virJSONValue) reply = NULL; + if (!cmd) return -1; @@ -1630,8 +1624,6 @@ int qemuMonitorJSONSystemPowerdown(qemuMonitor *mon) ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -1640,11 +1632,11 @@ int qemuMonitorJSONSetLink(qemuMonitor *mon, virDomainNetInterfaceLinkState state) { int ret = -1; - virJSONValue *reply = NULL; - virJSONValue *cmd = qemuMonitorJSONMakeCommand("set_link", - "s:name", name, - "b:up", state != VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DOWN, - NULL); + g_autoptr(virJSONValue) reply = NULL; + g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("set_link", + "s:name", name, + "b:up", state != VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DOWN, + NULL); if (!cmd) return -1; @@ -1657,16 +1649,15 @@ int qemuMonitorJSONSetLink(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } int qemuMonitorJSONSystemReset(qemuMonitor *mon) { int ret = -1; - virJSONValue *cmd = qemuMonitorJSONMakeCommand("system_reset", NULL); - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("system_reset", NULL); + g_autoptr(virJSONValue) reply = NULL; + if (!cmd) return -1; @@ -1678,8 +1669,6 @@ int qemuMonitorJSONSystemReset(qemuMonitor *mon) ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -1857,8 +1846,8 @@ qemuMonitorJSONQueryCPUs(qemuMonitor *mon, bool fast) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; virJSONValue *data; if (fast) @@ -1883,8 +1872,6 @@ qemuMonitorJSONQueryCPUs(qemuMonitor *mon, ret = qemuMonitorJSONExtractCPUInfo(data, entries, nentries, fast); cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -2008,9 +1995,9 @@ qemuMonitorJSONGetBalloonInfo(qemuMonitor *mon, int ret = -1; virJSONValue *data; unsigned long long mem; - virJSONValue *cmd = qemuMonitorJSONMakeCommand("query-balloon", - NULL); - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("query-balloon", + NULL); + g_autoptr(virJSONValue) reply = NULL; *currmem = 0; @@ -2042,8 +2029,6 @@ qemuMonitorJSONGetBalloonInfo(qemuMonitor *mon, *currmem = (mem/1024); ret = 1; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -2091,8 +2076,8 @@ int qemuMonitorJSONGetMemoryStats(qemuMonitor *mon, unsigned int nr_stats) { int ret = -1; - virJSONValue *cmd = NULL; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; virJSONValue *data; virJSONValue *statsdata; unsigned long long mem; @@ -2164,8 +2149,6 @@ int qemuMonitorJSONGetMemoryStats(qemuMonitor *mon, ret = got; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } #undef GET_BALLOON_STATS @@ -2220,8 +2203,8 @@ qemuMonitorJSONSetDBusVMStateIdList(qemuMonitor *mon, static virJSONValue * qemuMonitorJSONQueryBlock(qemuMonitor *mon) { - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; virJSONValue *devices = NULL; if (!(cmd = qemuMonitorJSONMakeCommand("query-block", NULL))) @@ -2234,8 +2217,6 @@ qemuMonitorJSONQueryBlock(qemuMonitor *mon) devices = virJSONValueObjectStealArray(reply, "return"); cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return devices; } @@ -2305,8 +2286,7 @@ int qemuMonitorJSONGetBlockInfo(qemuMonitor *mon, { int ret = -1; size_t i; - - virJSONValue *devices; + g_autoptr(virJSONValue) devices = NULL; if (!(devices = qemuMonitorJSONQueryBlock(mon))) return -1; @@ -2373,7 +2353,6 @@ int qemuMonitorJSONGetBlockInfo(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(devices); return ret; } @@ -2686,7 +2665,7 @@ int qemuMonitorJSONBlockStatsUpdateCapacityBlockdev(qemuMonitor *mon, GHashTable *stats) { - virJSONValue *nodes; + g_autoptr(virJSONValue) nodes = NULL; int ret = -1; if (!(nodes = qemuMonitorJSONQueryNamedBlockNodes(mon, false))) @@ -2700,7 +2679,6 @@ qemuMonitorJSONBlockStatsUpdateCapacityBlockdev(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(nodes); return ret; } @@ -2873,8 +2851,8 @@ int qemuMonitorJSONBlockResize(qemuMonitor *mon, unsigned long long size) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; cmd = qemuMonitorJSONMakeCommand("block_resize", "S:device", device, @@ -2892,8 +2870,6 @@ int qemuMonitorJSONBlockResize(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -2904,12 +2880,13 @@ int qemuMonitorJSONSetPassword(qemuMonitor *mon, const char *action_if_connected) { int ret = -1; - virJSONValue *cmd = qemuMonitorJSONMakeCommand("set_password", - "s:protocol", protocol, - "s:password", password, - "s:connected", action_if_connected, - NULL); - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("set_password", + "s:protocol", protocol, + "s:password", password, + "s:connected", action_if_connected, + NULL); + g_autoptr(virJSONValue) reply = NULL; + if (!cmd) return -1; @@ -2921,8 +2898,6 @@ int qemuMonitorJSONSetPassword(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -2931,11 +2906,12 @@ int qemuMonitorJSONExpirePassword(qemuMonitor *mon, const char *expire_time) { int ret = -1; - virJSONValue *cmd = qemuMonitorJSONMakeCommand("expire_password", - "s:protocol", protocol, - "s:time", expire_time, - NULL); - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("expire_password", + "s:protocol", protocol, + "s:time", expire_time, + NULL); + g_autoptr(virJSONValue) reply = NULL; + if (!cmd) return -1; @@ -2947,8 +2923,6 @@ int qemuMonitorJSONExpirePassword(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -2958,10 +2932,11 @@ qemuMonitorJSONSetBalloon(qemuMonitor *mon, unsigned long long newmem) { int ret = -1; - virJSONValue *cmd = qemuMonitorJSONMakeCommand("balloon", - "U:value", newmem * 1024, - NULL); - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("balloon", + "U:value", newmem * 1024, + NULL); + g_autoptr(virJSONValue) reply = NULL; + if (!cmd) return -1; @@ -2982,8 +2957,6 @@ qemuMonitorJSONSetBalloon(qemuMonitor *mon, /* Real success */ ret = 1; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -2992,8 +2965,8 @@ int qemuMonitorJSONSetCPU(qemuMonitor *mon, int cpu, bool online) { int ret = -1; - virJSONValue *cmd = NULL; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; if (online) { cmd = qemuMonitorJSONMakeCommand("cpu-add", @@ -3013,8 +2986,6 @@ int qemuMonitorJSONSetCPU(qemuMonitor *mon, ret = qemuMonitorJSONCheckError(cmd, reply); cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -3031,11 +3002,12 @@ int qemuMonitorJSONEjectMedia(qemuMonitor *mon, bool force) { int ret = -1; - virJSONValue *cmd = qemuMonitorJSONMakeCommand("eject", - "s:device", dev_name, - "b:force", force ? 1 : 0, - NULL); - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("eject", + "s:device", dev_name, + "b:force", force ? 1 : 0, + NULL); + g_autoptr(virJSONValue) reply = NULL; + if (!cmd) return -1; @@ -3047,8 +3019,6 @@ int qemuMonitorJSONEjectMedia(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -3059,8 +3029,8 @@ int qemuMonitorJSONChangeMedia(qemuMonitor *mon, const char *format) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; cmd = qemuMonitorJSONMakeCommand("change", "s:device", dev_name, @@ -3079,8 +3049,6 @@ int qemuMonitorJSONChangeMedia(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -3092,12 +3060,13 @@ static int qemuMonitorJSONSaveMemory(qemuMonitor *mon, const char *path) { int ret = -1; - virJSONValue *cmd = qemuMonitorJSONMakeCommand(cmdtype, - "U:val", offset, - "U:size", length, - "s:filename", path, - NULL); - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand(cmdtype, + "U:val", offset, + "U:size", length, + "s:filename", path, + NULL); + g_autoptr(virJSONValue) reply = NULL; + if (!cmd) return -1; @@ -3109,8 +3078,6 @@ static int qemuMonitorJSONSaveMemory(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -3136,8 +3103,9 @@ int qemuMonitorJSONSetMigrationSpeed(qemuMonitor *mon, unsigned long bandwidth) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; + cmd = qemuMonitorJSONMakeCommand("migrate_set_speed", "U:value", bandwidth * 1024ULL * 1024ULL, NULL); @@ -3152,8 +3120,6 @@ int qemuMonitorJSONSetMigrationSpeed(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -3162,8 +3128,8 @@ int qemuMonitorJSONSetMigrationDowntime(qemuMonitor *mon, unsigned long long downtime) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; cmd = qemuMonitorJSONMakeCommand("migrate_set_downtime", "d:value", downtime / 1000.0, @@ -3179,8 +3145,6 @@ int qemuMonitorJSONSetMigrationDowntime(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -3190,8 +3154,8 @@ qemuMonitorJSONGetMigrationCacheSize(qemuMonitor *mon, unsigned long long *cacheSize) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; *cacheSize = 0; @@ -3213,8 +3177,6 @@ qemuMonitorJSONGetMigrationCacheSize(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -3224,8 +3186,8 @@ qemuMonitorJSONSetMigrationCacheSize(qemuMonitor *mon, unsigned long long cacheSize) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; cmd = qemuMonitorJSONMakeCommand("migrate-set-cache-size", "U:value", cacheSize, @@ -3241,8 +3203,6 @@ qemuMonitorJSONSetMigrationCacheSize(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -3252,8 +3212,8 @@ qemuMonitorJSONGetMigrationParams(qemuMonitor *mon, virJSONValue **params) { int ret = -1; - virJSONValue *cmd = NULL; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; *params = NULL; @@ -3270,8 +3230,6 @@ qemuMonitorJSONGetMigrationParams(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -3512,9 +3470,9 @@ int qemuMonitorJSONGetMigrationStats(qemuMonitor *mon, char **error) { int ret = -1; - virJSONValue *cmd = qemuMonitorJSONMakeCommand("query-migrate", - NULL); - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("query-migrate", + NULL); + g_autoptr(virJSONValue) reply = NULL; memset(stats, 0, sizeof(*stats)); @@ -3532,8 +3490,6 @@ int qemuMonitorJSONGetMigrationStats(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -3543,14 +3499,14 @@ int qemuMonitorJSONMigrate(qemuMonitor *mon, const char *uri) { int ret = -1; - virJSONValue *cmd = + g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("migrate", "b:detach", flags & QEMU_MONITOR_MIGRATE_BACKGROUND ? 1 : 0, "b:blk", flags & QEMU_MONITOR_MIGRATE_NON_SHARED_DISK ? 1 : 0, "b:inc", flags & QEMU_MONITOR_MIGRATE_NON_SHARED_INC ? 1 : 0, "s:uri", uri, NULL); - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) reply = NULL; if (!cmd) return -1; @@ -3563,16 +3519,14 @@ int qemuMonitorJSONMigrate(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } int qemuMonitorJSONMigrateCancel(qemuMonitor *mon) { int ret = -1; - virJSONValue *cmd = qemuMonitorJSONMakeCommand("migrate_cancel", NULL); - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("migrate_cancel", NULL); + g_autoptr(virJSONValue) reply = NULL; if (!cmd) return -1; @@ -3584,8 +3538,6 @@ int qemuMonitorJSONMigrateCancel(qemuMonitor *mon) ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -3603,8 +3555,8 @@ int qemuMonitorJSONQueryDump(qemuMonitor *mon, qemuMonitorDumpStats *stats) { - virJSONValue *cmd = qemuMonitorJSONMakeCommand("query-dump", NULL); - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("query-dump", NULL); + g_autoptr(virJSONValue) reply = NULL; virJSONValue *result = NULL; int ret = -1; @@ -3622,8 +3574,6 @@ qemuMonitorJSONQueryDump(qemuMonitor *mon, ret = qemuMonitorJSONExtractDumpStats(result, stats); cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -3633,8 +3583,8 @@ qemuMonitorJSONGetDumpGuestMemoryCapability(qemuMonitor *mon, const char *capability) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; virJSONValue *caps; virJSONValue *formats; size_t i; @@ -3674,8 +3624,6 @@ qemuMonitorJSONGetDumpGuestMemoryCapability(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -3686,8 +3634,8 @@ qemuMonitorJSONDump(qemuMonitor *mon, bool detach) { int ret = -1; - virJSONValue *cmd = NULL; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; cmd = qemuMonitorJSONMakeCommand("dump-guest-memory", "b:paging", false, @@ -3706,8 +3654,6 @@ qemuMonitorJSONDump(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -3719,15 +3665,16 @@ int qemuMonitorJSONGraphicsRelocate(qemuMonitor *mon, const char *tlsSubject) { int ret = -1; - virJSONValue *cmd = qemuMonitorJSONMakeCommand("client_migrate_info", - "s:protocol", - (type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE ? "spice" : "vnc"), - "s:hostname", hostname, - "i:port", port, - "i:tls-port", tlsPort, - "S:cert-subject", tlsSubject, - NULL); - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("client_migrate_info", + "s:protocol", + (type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE ? "spice" : "vnc"), + "s:hostname", hostname, + "i:port", port, + "i:tls-port", tlsPort, + "S:cert-subject", tlsSubject, + NULL); + g_autoptr(virJSONValue) reply = NULL; + if (!cmd) return -1; @@ -3739,8 +3686,6 @@ int qemuMonitorJSONGraphicsRelocate(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -3925,10 +3870,11 @@ int qemuMonitorJSONSendFileHandle(qemuMonitor *mon, int fd) { int ret = -1; - virJSONValue *cmd = qemuMonitorJSONMakeCommand("getfd", - "s:fdname", fdname, - NULL); - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("getfd", + "s:fdname", fdname, + NULL); + g_autoptr(virJSONValue) reply = NULL; + if (!cmd) return -1; @@ -3940,8 +3886,6 @@ int qemuMonitorJSONSendFileHandle(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -3950,10 +3894,11 @@ int qemuMonitorJSONCloseFileHandle(qemuMonitor *mon, const char *fdname) { int ret = -1; - virJSONValue *cmd = qemuMonitorJSONMakeCommand("closefd", - "s:fdname", fdname, - NULL); - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("closefd", + "s:fdname", fdname, + NULL); + g_autoptr(virJSONValue) reply = NULL; + if (!cmd) return -1; @@ -3965,8 +3910,6 @@ int qemuMonitorJSONCloseFileHandle(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -4189,10 +4132,10 @@ qemuMonitorJSONQueryRxFilter(qemuMonitor *mon, const char *alias, virNetDevRxFilter **filter) { int ret = -1; - virJSONValue *cmd = qemuMonitorJSONMakeCommand("query-rx-filter", - "s:name", alias, - NULL); - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("query-rx-filter", + "s:name", alias, + NULL); + g_autoptr(virJSONValue) reply = NULL; if (!cmd) goto cleanup; @@ -4208,8 +4151,6 @@ qemuMonitorJSONQueryRxFilter(qemuMonitor *mon, const char *alias, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -4298,9 +4239,9 @@ qemuMonitorJSONGetChardevInfo(qemuMonitor *mon, { int ret = -1; - virJSONValue *cmd = qemuMonitorJSONMakeCommand("query-chardev", - NULL); - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("query-chardev", + NULL); + g_autoptr(virJSONValue) reply = NULL; if (!cmd) return -1; @@ -4313,8 +4254,6 @@ qemuMonitorJSONGetChardevInfo(qemuMonitor *mon, ret = qemuMonitorJSONExtractChardevInfo(reply, info); cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -4323,8 +4262,8 @@ int qemuMonitorJSONDelDevice(qemuMonitor *mon, const char *devalias) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; cmd = qemuMonitorJSONMakeCommand("device_del", "s:id", devalias, @@ -4345,8 +4284,6 @@ int qemuMonitorJSONDelDevice(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -4494,8 +4431,8 @@ int qemuMonitorJSONTransaction(qemuMonitor *mon, virJSONValue **actions) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; cmd = qemuMonitorJSONMakeCommand("transaction", "a:actions", actions, @@ -4511,8 +4448,6 @@ qemuMonitorJSONTransaction(qemuMonitor *mon, virJSONValue **actions) ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -4532,8 +4467,8 @@ qemuMonitorJSONBlockCommit(qemuMonitor *mon, unsigned long long speed) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; virTristateBool autofinalize = VIR_TRISTATE_BOOL_ABSENT; virTristateBool autodismiss = VIR_TRISTATE_BOOL_ABSENT; @@ -4565,8 +4500,6 @@ qemuMonitorJSONBlockCommit(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -4611,7 +4544,7 @@ qemuMonitorJSONDiskNameLookup(qemuMonitor *mon, virStorageSource *target) { char *ret = NULL; - virJSONValue *devices; + g_autoptr(virJSONValue) devices = NULL; size_t i; if (!(devices = qemuMonitorJSONQueryBlock(mon))) @@ -4645,8 +4578,6 @@ qemuMonitorJSONDiskNameLookup(qemuMonitor *mon, device); cleanup: - virJSONValueFree(devices); - return ret; } @@ -4655,8 +4586,8 @@ int qemuMonitorJSONArbitraryCommand(qemuMonitor *mon, const char *cmd_str, char **reply_str) { - virJSONValue *cmd = NULL; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; int ret = -1; if (!(cmd = virJSONValueFromString(cmd_str))) @@ -4671,16 +4602,14 @@ int qemuMonitorJSONArbitraryCommand(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } int qemuMonitorJSONInjectNMI(qemuMonitor *mon) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; cmd = qemuMonitorJSONMakeCommand("inject-nmi", NULL); if (!cmd) @@ -4694,8 +4623,6 @@ int qemuMonitorJSONInjectNMI(qemuMonitor *mon) ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -4705,16 +4632,17 @@ int qemuMonitorJSONSendKey(qemuMonitor *mon, unsigned int nkeycodes) { int ret = -1; - virJSONValue *cmd = NULL; - virJSONValue *reply = NULL; - virJSONValue *keys = NULL; - virJSONValue *key = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; + g_autoptr(virJSONValue) keys = NULL; size_t i; /* create the key data array */ keys = virJSONValueNewArray(); for (i = 0; i < nkeycodes; i++) { + g_autoptr(virJSONValue) key = NULL; + if (keycodes[i] > 0xffff) { virReportError(VIR_ERR_OPERATION_FAILED, _("keycode %zu is invalid: 0x%X"), i, keycodes[i]); @@ -4751,10 +4679,6 @@ int qemuMonitorJSONSendKey(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); - virJSONValueFree(keys); - virJSONValueFree(key); return ret; } @@ -4764,8 +4688,8 @@ int qemuMonitorJSONScreendump(qemuMonitor *mon, const char *file) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; cmd = qemuMonitorJSONMakeCommand("screendump", "s:filename", file, @@ -4784,8 +4708,6 @@ int qemuMonitorJSONScreendump(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -4925,8 +4847,8 @@ qemuMonitorJSONBlockStream(qemuMonitor *mon, unsigned long long speed) { int ret = -1; - virJSONValue *cmd = NULL; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; virTristateBool autofinalize = VIR_TRISTATE_BOOL_ABSENT; virTristateBool autodismiss = VIR_TRISTATE_BOOL_ABSENT; @@ -4956,8 +4878,6 @@ qemuMonitorJSONBlockStream(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -4992,8 +4912,8 @@ qemuMonitorJSONBlockJobSetSpeed(qemuMonitor *mon, unsigned long long speed) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; if (!(cmd = qemuMonitorJSONMakeCommand("block-job-set-speed", "s:device", jobname, @@ -5010,8 +4930,6 @@ qemuMonitorJSONBlockJobSetSpeed(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -5021,8 +4939,8 @@ qemuMonitorJSONDrivePivot(qemuMonitor *mon, const char *jobname) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; cmd = qemuMonitorJSONMakeCommand("block-job-complete", "s:device", jobname, @@ -5038,8 +4956,6 @@ qemuMonitorJSONDrivePivot(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -5094,8 +5010,8 @@ int qemuMonitorJSONOpenGraphics(qemuMonitor *mon, bool skipauth) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; cmd = qemuMonitorJSONMakeCommand("add_client", "s:protocol", protocol, @@ -5114,8 +5030,6 @@ int qemuMonitorJSONOpenGraphics(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -5266,21 +5180,20 @@ int qemuMonitorJSONGetBlockIoThrottle(qemuMonitor *mon, virDomainBlockIoTuneInfo *reply) { int ret = -1; - virJSONValue *devices = NULL; + g_autoptr(virJSONValue) devices = NULL; if (!(devices = qemuMonitorJSONQueryBlock(mon))) return -1; ret = qemuMonitorJSONBlockIoThrottleInfo(devices, drivealias, qdevid, reply); - virJSONValueFree(devices); return ret; } int qemuMonitorJSONSystemWakeup(qemuMonitor *mon) { int ret = -1; - virJSONValue *cmd = NULL; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; cmd = qemuMonitorJSONMakeCommand("system_wakeup", NULL); if (!cmd) @@ -5294,8 +5207,6 @@ int qemuMonitorJSONSystemWakeup(qemuMonitor *mon) ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -5306,8 +5217,8 @@ int qemuMonitorJSONGetVersion(qemuMonitor *mon, char **package) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; virJSONValue *data; virJSONValue *qemu; @@ -5361,8 +5272,6 @@ int qemuMonitorJSONGetVersion(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -5371,8 +5280,8 @@ int qemuMonitorJSONGetMachines(qemuMonitor *mon, qemuMonitorMachineInfo ***machines) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; virJSONValue *data; qemuMonitorMachineInfo **infolist = NULL; size_t n = 0; @@ -5484,8 +5393,6 @@ int qemuMonitorJSONGetMachines(qemuMonitor *mon, qemuMonitorMachineInfoFree(infolist[i]); VIR_FREE(infolist); } - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -5615,15 +5522,14 @@ static virJSONValue * qemuMonitorJSONMakeCPUModel(virCPUDef *cpu, bool migratable) { - virJSONValue *model = virJSONValueNewObject(); - virJSONValue *props = NULL; + g_autoptr(virJSONValue) model = virJSONValueNewObject(); size_t i; if (virJSONValueObjectAppendString(model, "name", cpu->model) < 0) goto error; if (cpu->nfeatures || !migratable) { - props = virJSONValueNewObject(); + g_autoptr(virJSONValue) props = virJSONValueNewObject(); for (i = 0; i < cpu->nfeatures; i++) { char *name = cpu->features[i].name; @@ -5648,11 +5554,9 @@ qemuMonitorJSONMakeCPUModel(virCPUDef *cpu, goto error; } - return model; + return g_steal_pointer(&model); error: - virJSONValueFree(model); - virJSONValueFree(props); return NULL; } @@ -5978,8 +5882,8 @@ int qemuMonitorJSONGetKVMState(qemuMonitor *mon, bool *present) { int ret = -1; - virJSONValue *cmd = NULL; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; virJSONValue *data = NULL; /* Safe defaults */ @@ -6006,8 +5910,6 @@ int qemuMonitorJSONGetKVMState(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -6063,8 +5965,8 @@ int qemuMonitorJSONGetObjectListPaths(qemuMonitor *mon, qemuMonitorJSONListPath ***paths) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; virJSONValue *data; qemuMonitorJSONListPath **pathlist = NULL; size_t n = 0; @@ -6125,8 +6027,6 @@ int qemuMonitorJSONGetObjectListPaths(qemuMonitor *mon, qemuMonitorJSONListPathFree(pathlist[i]); VIR_FREE(pathlist); } - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -6146,8 +6046,8 @@ int qemuMonitorJSONGetObjectProperty(qemuMonitor *mon, qemuMonitorJSONObjectProperty *prop) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; virJSONValue *data; const char *tmp; @@ -6210,9 +6110,6 @@ int qemuMonitorJSONGetObjectProperty(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); - return ret; } @@ -6259,8 +6156,8 @@ int qemuMonitorJSONSetObjectProperty(qemuMonitor *mon, qemuMonitorJSONObjectProperty *prop) { int ret = -1; - virJSONValue *cmd = NULL; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; switch ((qemuMonitorJSONObjectPropertyType) prop->type) { /* Simple cases of boolean, int, long, uint, ulong, double, and string @@ -6305,9 +6202,6 @@ int qemuMonitorJSONSetObjectProperty(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); - return ret; } #undef MAKE_SET_CMD @@ -6439,8 +6333,8 @@ qemuMonitorJSONGetTargetArch(qemuMonitor *mon) { char *ret = NULL; const char *arch; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; virJSONValue *data; if (!(cmd = qemuMonitorJSONMakeCommand("query-target", NULL))) @@ -6463,8 +6357,6 @@ qemuMonitorJSONGetTargetArch(qemuMonitor *mon) ret = g_strdup(arch); cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -6563,8 +6455,8 @@ qemuMonitorJSONGetGICCapabilities(qemuMonitor *mon, virGICCapability **capabilities) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; virJSONValue *caps; virGICCapability *list = NULL; size_t i; @@ -6643,8 +6535,6 @@ qemuMonitorJSONGetGICCapabilities(qemuMonitor *mon, cleanup: VIR_FREE(list); - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -6669,8 +6559,8 @@ qemuMonitorJSONGetSEVCapabilities(qemuMonitor *mon, virSEVCapability **capabilities) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; virJSONValue *caps; const char *pdh = NULL; const char *cert_chain = NULL; @@ -6738,9 +6628,6 @@ qemuMonitorJSONGetSEVCapabilities(qemuMonitor *mon, *capabilities = g_steal_pointer(&capability); ret = 1; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); - return ret; } @@ -6748,38 +6635,34 @@ static virJSONValue * qemuMonitorJSONBuildInetSocketAddress(const char *host, const char *port) { - virJSONValue *addr = NULL; - virJSONValue *data = NULL; + g_autoptr(virJSONValue) addr = NULL; + g_autoptr(virJSONValue) data = NULL; if (virJSONValueObjectCreate(&data, "s:host", host, "s:port", port, NULL) < 0) return NULL; if (virJSONValueObjectCreate(&addr, "s:type", "inet", - "a:data", &data, NULL) < 0) { - virJSONValueFree(data); + "a:data", &data, NULL) < 0) return NULL; - } - return addr; + return g_steal_pointer(&addr); } static virJSONValue * qemuMonitorJSONBuildUnixSocketAddress(const char *path) { - virJSONValue *addr = NULL; - virJSONValue *data = NULL; + g_autoptr(virJSONValue) addr = NULL; + g_autoptr(virJSONValue) data = NULL; if (virJSONValueObjectCreate(&data, "s:path", path, NULL) < 0) return NULL; if (virJSONValueObjectCreate(&addr, "s:type", "unix", - "a:data", &data, NULL) < 0) { - virJSONValueFree(data); + "a:data", &data, NULL) < 0) return NULL; - } - return addr; + return g_steal_pointer(&addr); } int @@ -6788,9 +6671,9 @@ qemuMonitorJSONNBDServerStart(qemuMonitor *mon, const char *tls_alias) { int ret = -1; - virJSONValue *cmd = NULL; - virJSONValue *reply = NULL; - virJSONValue *addr = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; + g_autoptr(virJSONValue) addr = NULL; char *port_str = NULL; switch ((virStorageNetHostTransport)server->transport) { @@ -6826,9 +6709,6 @@ qemuMonitorJSONNBDServerStart(qemuMonitor *mon, cleanup: VIR_FREE(port_str); - virJSONValueFree(reply); - virJSONValueFree(cmd); - virJSONValueFree(addr); return ret; } @@ -6840,8 +6720,8 @@ qemuMonitorJSONNBDServerAdd(qemuMonitor *mon, const char *bitmap) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; /* Note: bitmap must be NULL if QEMU_CAPS_NBD_BITMAP is lacking */ if (!(cmd = qemuMonitorJSONMakeCommand("nbd-server-add", @@ -6860,8 +6740,6 @@ qemuMonitorJSONNBDServerAdd(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -6869,8 +6747,8 @@ int qemuMonitorJSONNBDServerStop(qemuMonitor *mon) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; if (!(cmd = qemuMonitorJSONMakeCommand("nbd-server-stop", NULL))) @@ -6884,8 +6762,6 @@ qemuMonitorJSONNBDServerStop(qemuMonitor *mon) ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -6966,9 +6842,9 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, const virDomainChrSourceDef *chr) { virJSONValue *ret = NULL; - virJSONValue *backend = virJSONValueNewObject(); - virJSONValue *data = virJSONValueNewObject(); - virJSONValue *addr = NULL; + g_autoptr(virJSONValue) backend = virJSONValueNewObject(); + g_autoptr(virJSONValue) data = virJSONValueNewObject(); + g_autoptr(virJSONValue) addr = NULL; const char *backend_type = NULL; const char *host; const char *port; @@ -7122,9 +6998,6 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, cleanup: VIR_FREE(tlsalias); - virJSONValueFree(addr); - virJSONValueFree(data); - virJSONValueFree(backend); return ret; } @@ -7135,8 +7008,8 @@ qemuMonitorJSONAttachCharDev(qemuMonitor *mon, virDomainChrSourceDef *chr) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; if (!(cmd = qemuMonitorJSONAttachCharDevCommand(chrID, chr))) return ret; @@ -7168,8 +7041,6 @@ qemuMonitorJSONAttachCharDev(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -7178,8 +7049,8 @@ qemuMonitorJSONDetachCharDev(qemuMonitor *mon, const char *chrID) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; if (!(cmd = qemuMonitorJSONMakeCommand("chardev-remove", "s:id", chrID, @@ -7194,8 +7065,6 @@ qemuMonitorJSONDetachCharDev(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -7314,8 +7183,8 @@ qemuMonitorJSONGetCPUx86Data(qemuMonitor *mon, const char *property, virCPUData **cpudata) { - virJSONValue *cmd = NULL; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; virJSONValue *data; int ret = -1; @@ -7338,8 +7207,6 @@ qemuMonitorJSONGetCPUx86Data(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -7351,8 +7218,8 @@ qemuMonitorJSONGetCPUx86Data(qemuMonitor *mon, static int qemuMonitorJSONCheckCPUx86(qemuMonitor *mon) { - virJSONValue *cmd = NULL; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; virJSONValue *data; size_t i; size_t n; @@ -7394,8 +7261,6 @@ qemuMonitorJSONCheckCPUx86(qemuMonitor *mon) ret = 1; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -7580,8 +7445,8 @@ int qemuMonitorJSONRTCResetReinjection(qemuMonitor *mon) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; if (!(cmd = qemuMonitorJSONMakeCommand("rtc-reset-reinjection", NULL))) @@ -7595,8 +7460,6 @@ qemuMonitorJSONRTCResetReinjection(qemuMonitor *mon) ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -7612,8 +7475,8 @@ qemuMonitorJSONGetIOThreads(qemuMonitor *mon, int *niothreads) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; virJSONValue *data; qemuMonitorIOThreadInfo **infolist = NULL; size_t n = 0; @@ -7696,8 +7559,6 @@ qemuMonitorJSONGetIOThreads(qemuMonitor *mon, VIR_FREE(infolist[i]); VIR_FREE(infolist); } - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -7740,8 +7601,8 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon, GHashTable *info) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; virJSONValue *data = NULL; size_t i; @@ -7841,8 +7702,6 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -8012,8 +7871,8 @@ int qemuMonitorJSONMigrateStartPostCopy(qemuMonitor *mon) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; if (!(cmd = qemuMonitorJSONMakeCommand("migrate-start-postcopy", NULL))) return -1; @@ -8024,8 +7883,6 @@ qemuMonitorJSONMigrateStartPostCopy(qemuMonitor *mon) ret = qemuMonitorJSONCheckError(cmd, reply); cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -8036,8 +7893,8 @@ qemuMonitorJSONMigrateContinue(qemuMonitor *mon, { const char *statusStr = qemuMonitorMigrationStatusTypeToString(status); int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; if (!(cmd = qemuMonitorJSONMakeCommand("migrate-continue", "s:state", statusStr, @@ -8050,8 +7907,6 @@ qemuMonitorJSONMigrateContinue(qemuMonitor *mon, ret = qemuMonitorJSONCheckError(cmd, reply); cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -8061,8 +7916,8 @@ qemuMonitorJSONGetRTCTime(qemuMonitor *mon, struct tm *tm) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; virJSONValue *data; if (!(cmd = qemuMonitorJSONMakeCommand("qom-get", @@ -8092,8 +7947,6 @@ qemuMonitorJSONGetRTCTime(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -8228,8 +8081,8 @@ qemuMonitorJSONGetHotpluggableCPUs(qemuMonitor *mon, int ret = -1; size_t i; virJSONValue *data; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; virJSONValue *vcpu; if (!(cmd = qemuMonitorJSONMakeCommand("query-hotpluggable-cpus", NULL))) @@ -8261,8 +8114,6 @@ qemuMonitorJSONGetHotpluggableCPUs(qemuMonitor *mon, cleanup: qemuMonitorQueryHotpluggableCpusFree(info, ninfo); - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -8270,8 +8121,8 @@ qemuMonitorJSONGetHotpluggableCPUs(qemuMonitor *mon, virJSONValue * qemuMonitorJSONQueryQMPSchema(qemuMonitor *mon) { - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; virJSONValue *ret = NULL; if (!(cmd = qemuMonitorJSONMakeCommand("query-qmp-schema", NULL))) @@ -8286,9 +8137,6 @@ qemuMonitorJSONQueryQMPSchema(qemuMonitor *mon) ret = virJSONValueObjectStealArray(reply, "return"); cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); - return ret; } @@ -8298,8 +8146,8 @@ qemuMonitorJSONSetBlockThreshold(qemuMonitor *mon, const char *nodename, unsigned long long threshold) { - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; int ret = -1; if (!(cmd = qemuMonitorJSONMakeCommand("block-set-write-threshold", @@ -8317,9 +8165,6 @@ qemuMonitorJSONSetBlockThreshold(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); - return ret; } @@ -8461,8 +8306,8 @@ qemuMonitorJSONBlockdevTrayOpen(qemuMonitor *mon, const char *id, bool force) { - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; int ret = -1; if (!(cmd = qemuMonitorJSONMakeCommand("blockdev-open-tray", @@ -8479,8 +8324,6 @@ qemuMonitorJSONBlockdevTrayOpen(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -8489,8 +8332,8 @@ int qemuMonitorJSONBlockdevTrayClose(qemuMonitor *mon, const char *id) { - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; int ret = -1; if (!(cmd = qemuMonitorJSONMakeCommand("blockdev-close-tray", @@ -8506,8 +8349,6 @@ qemuMonitorJSONBlockdevTrayClose(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -8516,8 +8357,8 @@ int qemuMonitorJSONBlockdevMediumRemove(qemuMonitor *mon, const char *id) { - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; int ret = -1; if (!(cmd = qemuMonitorJSONMakeCommand("blockdev-remove-medium", @@ -8533,8 +8374,6 @@ qemuMonitorJSONBlockdevMediumRemove(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -8544,8 +8383,8 @@ qemuMonitorJSONBlockdevMediumInsert(qemuMonitor *mon, const char *id, const char *nodename) { - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; int ret = -1; if (!(cmd = qemuMonitorJSONMakeCommand("blockdev-insert-medium", @@ -8563,8 +8402,6 @@ qemuMonitorJSONBlockdevMediumInsert(qemuMonitor *mon, ret = 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -8584,8 +8421,8 @@ qemuMonitorJSONGetSEVMeasurement(qemuMonitor *mon) { const char *tmp; char *measurement = NULL; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; virJSONValue *data; if (!(cmd = qemuMonitorJSONMakeCommand("query-sev-launch-measure", NULL))) @@ -8605,8 +8442,6 @@ qemuMonitorJSONGetSEVMeasurement(qemuMonitor *mon) measurement = g_strdup(tmp); cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return measurement; } @@ -8666,8 +8501,8 @@ qemuMonitorJSONGetPRManagerInfo(qemuMonitor *mon, GHashTable *info) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; if (!(cmd = qemuMonitorJSONMakeCommand("query-pr-managers", NULL))) @@ -8681,8 +8516,6 @@ qemuMonitorJSONGetPRManagerInfo(qemuMonitor *mon, ret = qemuMonitorJSONExtractPRManagerInfo(reply, info); cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -8716,8 +8549,8 @@ qemuMonitorJSONGetCurrentMachineInfo(qemuMonitor *mon, qemuMonitorCurrentMachineInfo *info) { int ret = -1; - virJSONValue *cmd; - virJSONValue *reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; if (!(cmd = qemuMonitorJSONMakeCommand("query-current-machine", NULL))) @@ -8732,8 +8565,6 @@ qemuMonitorJSONGetCurrentMachineInfo(qemuMonitor *mon, ret = qemuMonitorJSONExtractCurrentMachineInfo(reply, info); cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } -- 2.32.0

Let's replace VIR_FREE() calls with g_autofree. Not all calls can be replaced though - the legitimate ones are kept (e.g. those which free array, or which free a struct for which we don't have g_autoptr() yet, and so on). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_monitor_json.c | 37 +++++++++++------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 1eb0b3b54c..cd4a37a685 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -175,7 +175,7 @@ qemuMonitorJSONIOProcessEvent(qemuMonitor *mon, const char *type; qemuEventHandler *handler; virJSONValue *data; - char *details = NULL; + g_autofree char *details = NULL; virJSONValue *timestamp; long long seconds = -1; unsigned int micros = 0; @@ -199,7 +199,6 @@ qemuMonitorJSONIOProcessEvent(qemuMonitor *mon, µs)); } qemuMonitorEmitEvent(mon, type, seconds, micros, details); - VIR_FREE(details); handler = bsearch(type, eventHandlers, G_N_ELEMENTS(eventHandlers), sizeof(eventHandlers[0]), qemuMonitorEventCompare); @@ -270,16 +269,12 @@ int qemuMonitorJSONIOProcess(qemuMonitor *mon, if (nl) { int got = nl - (data + used); - char *line; - line = g_strndup(data + used, got); + g_autofree char *line = g_strndup(data + used, got); + used += got + strlen(LINE_ENDING); line[got] = '\0'; /* kill \n */ - if (qemuMonitorJSONIOProcessLine(mon, line, msg) < 0) { - VIR_FREE(line); + if (qemuMonitorJSONIOProcessLine(mon, line, msg) < 0) return -1; - } - - VIR_FREE(line); } else { break; } @@ -6458,7 +6453,7 @@ qemuMonitorJSONGetGICCapabilities(qemuMonitor *mon, g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; virJSONValue *caps; - virGICCapability *list = NULL; + g_autofree virGICCapability *list = NULL; size_t i; size_t n; @@ -6534,8 +6529,6 @@ qemuMonitorJSONGetGICCapabilities(qemuMonitor *mon, *capabilities = g_steal_pointer(&list); cleanup: - VIR_FREE(list); - return ret; } @@ -6674,7 +6667,7 @@ qemuMonitorJSONNBDServerStart(qemuMonitor *mon, g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; g_autoptr(virJSONValue) addr = NULL; - char *port_str = NULL; + g_autofree char *port_str = NULL; switch ((virStorageNetHostTransport)server->transport) { case VIR_STORAGE_NET_HOST_TRANS_TCP: @@ -6708,7 +6701,6 @@ qemuMonitorJSONNBDServerStart(qemuMonitor *mon, ret = 0; cleanup: - VIR_FREE(port_str); return ret; } @@ -6848,7 +6840,7 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, const char *backend_type = NULL; const char *host; const char *port; - char *tlsalias = NULL; + g_autofree char *tlsalias = NULL; bool telnet; switch ((virDomainChrType)chr->type) { @@ -6997,7 +6989,6 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, goto cleanup; cleanup: - VIR_FREE(tlsalias); return ret; } @@ -7568,7 +7559,7 @@ qemuMonitorJSONSetIOThread(qemuMonitor *mon, qemuMonitorIOThreadInfo *iothreadInfo) { int ret = -1; - char *path = NULL; + g_autofree char *path = NULL; qemuMonitorJSONObjectProperty prop; path = g_strdup_printf("/objects/iothread%u", iothreadInfo->iothread_id); @@ -7591,7 +7582,6 @@ qemuMonitorJSONSetIOThread(qemuMonitor *mon, ret = 0; cleanup: - VIR_FREE(path); return ret; } @@ -7724,7 +7714,7 @@ qemuMonitorJSONFindObjectPathByAlias(qemuMonitor *mon, char **path) { qemuMonitorJSONListPath **paths = NULL; - char *child = NULL; + g_autofree char *child = NULL; int npaths; int ret = -1; size_t i; @@ -7750,7 +7740,6 @@ qemuMonitorJSONFindObjectPathByAlias(qemuMonitor *mon, for (i = 0; i < npaths; i++) qemuMonitorJSONListPathFree(paths[i]); VIR_FREE(paths); - VIR_FREE(child); return ret; } @@ -7775,7 +7764,6 @@ qemuMonitorJSONFindObjectPathByName(qemuMonitor *mon, { ssize_t i, npaths = 0; int ret = -2; - char *nextpath = NULL; qemuMonitorJSONListPath **paths = NULL; VIR_DEBUG("Searching for '%s' Object Path starting at '%s'", name, curpath); @@ -7797,10 +7785,9 @@ qemuMonitorJSONFindObjectPathByName(qemuMonitor *mon, * traversed looking for more entries */ if (paths[i]->type && STRPREFIX(paths[i]->type, "child<")) { - nextpath = g_strdup_printf("%s/%s", curpath, paths[i]->name); + g_autofree char *nextpath = g_strdup_printf("%s/%s", curpath, paths[i]->name); ret = qemuMonitorJSONFindObjectPathByName(mon, nextpath, name, path); - VIR_FREE(nextpath); } } @@ -7808,7 +7795,6 @@ qemuMonitorJSONFindObjectPathByName(qemuMonitor *mon, for (i = 0; i < npaths; i++) qemuMonitorJSONListPathFree(paths[i]); VIR_FREE(paths); - VIR_FREE(nextpath); return ret; } @@ -7831,7 +7817,7 @@ qemuMonitorJSONFindLinkPath(qemuMonitor *mon, const char *alias, char **path) { - char *linkname = NULL; + g_autofree char *linkname = NULL; int ret = -1; if (alias) { @@ -7843,7 +7829,6 @@ qemuMonitorJSONFindLinkPath(qemuMonitor *mon, linkname = g_strdup_printf("link<%s>", name); ret = qemuMonitorJSONFindObjectPathByName(mon, "/", linkname, path); - VIR_FREE(linkname); return ret; } -- 2.32.0

After previous cleanups, some 'cleanup' labels were rendered needless - they contain nothing more than a return statement. Well, those labels can be dropped and 'goto cleanup' can be replaced with return statement directly. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_monitor_json.c | 1035 ++++++++++++---------------------- 1 file changed, 368 insertions(+), 667 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index cd4a37a685..bb76ac7d37 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -216,25 +216,24 @@ qemuMonitorJSONIOProcessLine(qemuMonitor *mon, qemuMonitorMessage *msg) { g_autoptr(virJSONValue) obj = NULL; - int ret = -1; VIR_DEBUG("Line [%s]", line); if (!(obj = virJSONValueFromString(line))) - goto cleanup; + return -1; if (virJSONValueGetType(obj) != VIR_JSON_TYPE_OBJECT) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Parsed JSON reply '%s' isn't an object"), line); - goto cleanup; + return -1; } if (virJSONValueObjectHasKey(obj, "QMP") == 1) { - ret = 0; + return 0; } else if (virJSONValueObjectHasKey(obj, "event") == 1) { PROBE(QEMU_MONITOR_RECV_EVENT, "mon=%p event=%s", mon, line); - ret = qemuMonitorJSONIOProcessEvent(mon, obj); + return qemuMonitorJSONIOProcessEvent(mon, obj); } else if (virJSONValueObjectHasKey(obj, "error") == 1 || virJSONValueObjectHasKey(obj, "return") == 1) { PROBE(QEMU_MONITOR_RECV_REPLY, @@ -242,7 +241,7 @@ qemuMonitorJSONIOProcessLine(qemuMonitor *mon, if (msg) { msg->rxObject = g_steal_pointer(&obj); msg->finished = 1; - ret = 0; + return 0; } else { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unexpected JSON reply '%s'"), line); @@ -252,8 +251,7 @@ qemuMonitorJSONIOProcessLine(qemuMonitor *mon, _("Unknown JSON reply '%s'"), line); } - cleanup: - return ret; + return -1; } int qemuMonitorJSONIOProcess(qemuMonitor *mon, @@ -307,12 +305,12 @@ qemuMonitorJSONCommandWithFd(qemuMonitor *mon, if (virJSONValueObjectAppendString(cmd, "id", id) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to append command 'id' string")); - goto cleanup; + return -1; } } if (virJSONValueToBuffer(cmd, &cmdbuf, false) < 0) - goto cleanup; + return -1; virBufferAddLit(&cmdbuf, "\r\n"); msg.txLength = virBufferUse(&cmdbuf); @@ -331,7 +329,6 @@ qemuMonitorJSONCommandWithFd(qemuMonitor *mon, } } - cleanup: return ret; } @@ -1455,33 +1452,29 @@ qemuMonitorJSONHumanCommand(qemuMonitor *mon, g_autoptr(virJSONValue) reply = NULL; virJSONValue *obj; const char *data; - int ret = -1; cmd = qemuMonitorJSONMakeCommand("human-monitor-command", "s:command-line", cmd_str, NULL); if (!cmd || qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONHasError(reply, "CommandNotFound")) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, _("Human monitor command is not available to run %s"), cmd_str); - goto cleanup; + return -1; } if (qemuMonitorJSONCheckError(cmd, reply)) - goto cleanup; + return -1; obj = virJSONValueObjectGet(reply, "return"); data = virJSONValueGetString(obj); *reply_str = g_strdup(NULLSTR_EMPTY(data)); - ret = 0; - - cleanup: - return ret; + return 0; } @@ -1542,7 +1535,6 @@ qemuMonitorJSONStartCPUs(qemuMonitor *mon) int qemuMonitorJSONStopCPUs(qemuMonitor *mon) { - int ret = -1; g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("stop", NULL); g_autoptr(virJSONValue) reply = NULL; @@ -1550,14 +1542,12 @@ qemuMonitorJSONStopCPUs(qemuMonitor *mon) return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } @@ -1604,7 +1594,6 @@ qemuMonitorJSONGetStatus(qemuMonitor *mon, int qemuMonitorJSONSystemPowerdown(qemuMonitor *mon) { - int ret = -1; g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("system_powerdown", NULL); g_autoptr(virJSONValue) reply = NULL; @@ -1612,21 +1601,18 @@ int qemuMonitorJSONSystemPowerdown(qemuMonitor *mon) return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } int qemuMonitorJSONSetLink(qemuMonitor *mon, const char *name, virDomainNetInterfaceLinkState state) { - int ret = -1; g_autoptr(virJSONValue) reply = NULL; g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("set_link", "s:name", name, @@ -1637,19 +1623,16 @@ int qemuMonitorJSONSetLink(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } int qemuMonitorJSONSystemReset(qemuMonitor *mon) { - int ret = -1; g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("system_reset", NULL); g_autoptr(virJSONValue) reply = NULL; @@ -1657,14 +1640,12 @@ int qemuMonitorJSONSystemReset(qemuMonitor *mon) return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } @@ -1840,7 +1821,6 @@ qemuMonitorJSONQueryCPUs(qemuMonitor *mon, bool force, bool fast) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; virJSONValue *data; @@ -1854,20 +1834,15 @@ qemuMonitorJSONQueryCPUs(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (force && qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - if (!(data = virJSONValueObjectGetArray(reply, "return"))) { - ret = -2; - goto cleanup; - } + if (!(data = virJSONValueObjectGetArray(reply, "return"))) + return -2; - ret = qemuMonitorJSONExtractCPUInfo(data, entries, nentries, fast); - - cleanup: - return ret; + return qemuMonitorJSONExtractCPUInfo(data, entries, nentries, fast); } @@ -1987,7 +1962,6 @@ int qemuMonitorJSONGetBalloonInfo(qemuMonitor *mon, unsigned long long *currmem) { - int ret = -1; virJSONValue *data; unsigned long long mem; g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("query-balloon", @@ -2000,31 +1974,28 @@ qemuMonitorJSONGetBalloonInfo(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; /* See if balloon soft-failed */ if (qemuMonitorJSONHasError(reply, "DeviceNotActive") || qemuMonitorJSONHasError(reply, "KVMMissingCap")) { - ret = 0; - goto cleanup; + return 0; } /* See if any other fatal error occurred */ if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) - goto cleanup; + return -1; data = virJSONValueObjectGetObject(reply, "return"); if (virJSONValueObjectGetNumberUlong(data, "actual", &mem) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("info balloon reply was missing balloon data")); - goto cleanup; + return -1; } *currmem = (mem/1024); - ret = 1; - cleanup: - return ret; + return 1; } @@ -2200,19 +2171,15 @@ qemuMonitorJSONQueryBlock(qemuMonitor *mon) { g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; - virJSONValue *devices = NULL; if (!(cmd = qemuMonitorJSONMakeCommand("query-block", NULL))) return NULL; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0 || qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) - goto cleanup; + return NULL; - devices = virJSONValueObjectStealArray(reply, "return"); - - cleanup: - return devices; + return virJSONValueObjectStealArray(reply, "return"); } @@ -2279,7 +2246,6 @@ qemuMonitorJSONBlockInfoAdd(GHashTable *table, int qemuMonitorJSONGetBlockInfo(qemuMonitor *mon, GHashTable *table) { - int ret = -1; size_t i; g_autoptr(virJSONValue) devices = NULL; @@ -2295,10 +2261,10 @@ int qemuMonitorJSONGetBlockInfo(qemuMonitor *mon, const char *qdev; if (!(dev = qemuMonitorJSONGetBlockDev(devices, i))) - goto cleanup; + return -1; if (!(thisdev = qemuMonitorJSONGetBlockDevDevice(dev))) - goto cleanup; + return -1; thisdev = qemuAliasDiskDriveSkipPrefix(thisdev); qdev = virJSONValueObjectGetString(dev, "qdev"); @@ -2309,14 +2275,14 @@ int qemuMonitorJSONGetBlockInfo(qemuMonitor *mon, if (!qdev && !thisdev) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("query-block device entry was not in expected format")); - goto cleanup; + return -1; } if (virJSONValueObjectGetBoolean(dev, "removable", &info.removable) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot read %s value"), "removable"); - goto cleanup; + return -1; } /* 'tray_open' is present only if the device has a tray */ @@ -2334,21 +2300,19 @@ int qemuMonitorJSONGetBlockInfo(qemuMonitor *mon, if ((status = virJSONValueObjectGetString(dev, "io-status"))) { info.io_status = qemuMonitorBlockIOStatusToError(status); if (info.io_status < 0) - goto cleanup; + return -1; } if (thisdev && qemuMonitorJSONBlockInfoAdd(table, &info, thisdev) < 0) - goto cleanup; + return -1; if (qdev && STRNEQ_NULLABLE(thisdev, qdev) && qemuMonitorJSONBlockInfoAdd(table, &info, qdev) < 0) - goto cleanup; + return -1; } - ret = 0; - cleanup: - return ret; + return 0; } @@ -2661,7 +2625,6 @@ qemuMonitorJSONBlockStatsUpdateCapacityBlockdev(qemuMonitor *mon, GHashTable *stats) { g_autoptr(virJSONValue) nodes = NULL; - int ret = -1; if (!(nodes = qemuMonitorJSONQueryNamedBlockNodes(mon, false))) return -1; @@ -2669,12 +2632,9 @@ qemuMonitorJSONBlockStatsUpdateCapacityBlockdev(qemuMonitor *mon, if (virJSONValueArrayForeachSteal(nodes, qemuMonitorJSONBlockStatsUpdateCapacityBlockdevWorker, stats) < 0) - goto cleanup; + return -1; - ret = 0; - - cleanup: - return ret; + return 0; } @@ -2845,7 +2805,6 @@ int qemuMonitorJSONBlockResize(qemuMonitor *mon, const char *nodename, unsigned long long size) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; @@ -2858,14 +2817,12 @@ int qemuMonitorJSONBlockResize(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } @@ -2874,7 +2831,6 @@ int qemuMonitorJSONSetPassword(qemuMonitor *mon, const char *password, const char *action_if_connected) { - int ret = -1; g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("set_password", "s:protocol", protocol, "s:password", password, @@ -2886,21 +2842,18 @@ int qemuMonitorJSONSetPassword(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } int qemuMonitorJSONExpirePassword(qemuMonitor *mon, const char *protocol, const char *expire_time) { - int ret = -1; g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("expire_password", "s:protocol", protocol, "s:time", expire_time, @@ -2911,14 +2864,12 @@ int qemuMonitorJSONExpirePassword(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } @@ -2926,7 +2877,6 @@ int qemuMonitorJSONSetBalloon(qemuMonitor *mon, unsigned long long newmem) { - int ret = -1; g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("balloon", "U:value", newmem * 1024, NULL); @@ -2936,30 +2886,26 @@ qemuMonitorJSONSetBalloon(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; /* See if balloon soft-failed */ if (qemuMonitorJSONHasError(reply, "DeviceNotActive") || qemuMonitorJSONHasError(reply, "KVMMissingCap")) { - ret = 0; - goto cleanup; + return 0; } /* See if any other fatal error occurred */ if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; /* Real success */ - ret = 1; - cleanup: - return ret; + return 1; } int qemuMonitorJSONSetCPU(qemuMonitor *mon, int cpu, bool online) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; @@ -2970,18 +2916,15 @@ int qemuMonitorJSONSetCPU(qemuMonitor *mon, } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("vCPU unplug is not supported by this QEMU")); - goto cleanup; + return -1; } if (!cmd) - goto cleanup; + return -1; - if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0) - goto cleanup; + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + return -1; - ret = qemuMonitorJSONCheckError(cmd, reply); - - cleanup: - return ret; + return qemuMonitorJSONCheckError(cmd, reply); } @@ -2996,7 +2939,6 @@ int qemuMonitorJSONEjectMedia(qemuMonitor *mon, const char *dev_name, bool force) { - int ret = -1; g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("eject", "s:device", dev_name, "b:force", force ? 1 : 0, @@ -3007,14 +2949,12 @@ int qemuMonitorJSONEjectMedia(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } @@ -3023,7 +2963,6 @@ int qemuMonitorJSONChangeMedia(qemuMonitor *mon, const char *newmedia, const char *format) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; @@ -3037,14 +2976,12 @@ int qemuMonitorJSONChangeMedia(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } @@ -3054,7 +2991,6 @@ static int qemuMonitorJSONSaveMemory(qemuMonitor *mon, unsigned long long length, const char *path) { - int ret = -1; g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand(cmdtype, "U:val", offset, "U:size", length, @@ -3066,14 +3002,12 @@ static int qemuMonitorJSONSaveMemory(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } @@ -3097,7 +3031,6 @@ int qemuMonitorJSONSavePhysicalMemory(qemuMonitor *mon, int qemuMonitorJSONSetMigrationSpeed(qemuMonitor *mon, unsigned long bandwidth) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; @@ -3108,21 +3041,18 @@ int qemuMonitorJSONSetMigrationSpeed(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } int qemuMonitorJSONSetMigrationDowntime(qemuMonitor *mon, unsigned long long downtime) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; @@ -3133,14 +3063,12 @@ int qemuMonitorJSONSetMigrationDowntime(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } @@ -3148,7 +3076,6 @@ int qemuMonitorJSONGetMigrationCacheSize(qemuMonitor *mon, unsigned long long *cacheSize) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; @@ -3159,20 +3086,18 @@ qemuMonitorJSONGetMigrationCacheSize(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_NUMBER) < 0) - goto cleanup; + return -1; if (virJSONValueObjectGetNumberUlong(reply, "return", cacheSize) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("invalid cache size in query-migrate-cache-size reply")); - goto cleanup; + return -1; } - ret = 0; - cleanup: - return ret; + return 0; } @@ -3180,7 +3105,6 @@ int qemuMonitorJSONSetMigrationCacheSize(qemuMonitor *mon, unsigned long long cacheSize) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; @@ -3191,14 +3115,12 @@ qemuMonitorJSONSetMigrationCacheSize(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } @@ -3206,7 +3128,6 @@ int qemuMonitorJSONGetMigrationParams(qemuMonitor *mon, virJSONValue **params) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; @@ -3216,16 +3137,13 @@ qemuMonitorJSONGetMigrationParams(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) - goto cleanup; + return -1; *params = virJSONValueObjectStealObject(reply, "return"); - ret = 0; - - cleanup: - return ret; + return 0; } int @@ -3464,7 +3382,6 @@ int qemuMonitorJSONGetMigrationStats(qemuMonitor *mon, qemuMonitorMigrationStats *stats, char **error) { - int ret = -1; g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("query-migrate", NULL); g_autoptr(virJSONValue) reply = NULL; @@ -3475,17 +3392,15 @@ int qemuMonitorJSONGetMigrationStats(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONGetMigrationStatsReply(reply, stats, error) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } @@ -3493,7 +3408,6 @@ int qemuMonitorJSONMigrate(qemuMonitor *mon, unsigned int flags, const char *uri) { - int ret = -1; g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("migrate", "b:detach", flags & QEMU_MONITOR_MIGRATE_BACKGROUND ? 1 : 0, @@ -3507,33 +3421,28 @@ int qemuMonitorJSONMigrate(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } int qemuMonitorJSONMigrateCancel(qemuMonitor *mon) { - int ret = -1; g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("migrate_cancel", NULL); g_autoptr(virJSONValue) reply = NULL; if (!cmd) return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } @@ -3553,23 +3462,19 @@ qemuMonitorJSONQueryDump(qemuMonitor *mon, g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("query-dump", NULL); g_autoptr(virJSONValue) reply = NULL; virJSONValue *result = NULL; - int ret = -1; if (!cmd) return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) - goto cleanup; + return -1; result = virJSONValueObjectGetObject(reply, "return"); - ret = qemuMonitorJSONExtractDumpStats(result, stats); - - cleanup: - return ret; + return qemuMonitorJSONExtractDumpStats(result, stats); } @@ -3577,7 +3482,6 @@ int qemuMonitorJSONGetDumpGuestMemoryCapability(qemuMonitor *mon, const char *capability) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; virJSONValue *caps; @@ -3589,17 +3493,17 @@ qemuMonitorJSONGetDumpGuestMemoryCapability(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) - goto cleanup; + return -1; caps = virJSONValueObjectGetObject(reply, "return"); if (!(formats = virJSONValueObjectGetArray(caps, "formats"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing supported dump formats")); - goto cleanup; + return -1; } for (i = 0; i < virJSONValueArraySize(formats); i++) { @@ -3608,18 +3512,14 @@ qemuMonitorJSONGetDumpGuestMemoryCapability(qemuMonitor *mon, if (!dumpformat || virJSONValueGetType(dumpformat) != VIR_JSON_TYPE_STRING) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing entry in supported dump formats")); - goto cleanup; + return -1; } - if (STREQ(virJSONValueGetString(dumpformat), capability)) { - ret = 1; - goto cleanup; - } + if (STREQ(virJSONValueGetString(dumpformat), capability)) + return 1; } - ret = 0; - cleanup: - return ret; + return 0; } int @@ -3628,7 +3528,6 @@ qemuMonitorJSONDump(qemuMonitor *mon, const char *dumpformat, bool detach) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; @@ -3642,14 +3541,12 @@ qemuMonitorJSONDump(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } int qemuMonitorJSONGraphicsRelocate(qemuMonitor *mon, @@ -3659,7 +3556,6 @@ int qemuMonitorJSONGraphicsRelocate(qemuMonitor *mon, int tlsPort, const char *tlsSubject) { - int ret = -1; g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("client_migrate_info", "s:protocol", (type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE ? "spice" : "vnc"), @@ -3674,14 +3570,12 @@ int qemuMonitorJSONGraphicsRelocate(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } @@ -3864,7 +3758,6 @@ int qemuMonitorJSONSendFileHandle(qemuMonitor *mon, const char *fdname, int fd) { - int ret = -1; g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("getfd", "s:fdname", fdname, NULL); @@ -3874,21 +3767,18 @@ int qemuMonitorJSONSendFileHandle(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommandWithFd(mon, cmd, fd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } int qemuMonitorJSONCloseFileHandle(qemuMonitor *mon, const char *fdname) { - int ret = -1; g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("closefd", "s:fdname", fdname, NULL); @@ -3898,14 +3788,12 @@ int qemuMonitorJSONCloseFileHandle(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } @@ -3955,7 +3843,6 @@ static int qemuMonitorJSONQueryRxFilterParse(virJSONValue *msg, virNetDevRxFilter **filter) { - int ret = -1; const char *tmp; virJSONValue *returnArray; virJSONValue *entry; @@ -3966,21 +3853,21 @@ qemuMonitorJSONQueryRxFilterParse(virJSONValue *msg, g_autoptr(virNetDevRxFilter) fil = virNetDevRxFilterNew(); if (!fil) - goto cleanup; + return -1; returnArray = virJSONValueObjectGetArray(msg, "return"); if (!(entry = virJSONValueArrayGet(returnArray, 0))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("query -rx-filter return data missing array element")); - goto cleanup; + _("query-rx-filter return data missing array element")); + return -1; } if (!(tmp = virJSONValueObjectGetString(entry, "name"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing or invalid name " "in query-rx-filter response")); - goto cleanup; + return -1; } fil->name = g_strdup(tmp); if ((!(tmp = virJSONValueObjectGetString(entry, "main-mac"))) || @@ -3988,21 +3875,21 @@ qemuMonitorJSONQueryRxFilterParse(virJSONValue *msg, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing or invalid 'main-mac' " "in query-rx-filter response")); - goto cleanup; + return -1; } if (virJSONValueObjectGetBoolean(entry, "promiscuous", &fil->promiscuous) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing or invalid 'promiscuous' " "in query-rx-filter response")); - goto cleanup; + return -1; } if (virJSONValueObjectGetBoolean(entry, "broadcast-allowed", &fil->broadcastAllowed) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing or invalid 'broadcast-allowed' " "in query-rx-filter response")); - goto cleanup; + return -1; } if ((!(tmp = virJSONValueObjectGetString(entry, "unicast"))) || @@ -4011,21 +3898,21 @@ qemuMonitorJSONQueryRxFilterParse(virJSONValue *msg, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing or invalid 'unicast' " "in query-rx-filter response")); - goto cleanup; + return -1; } if (virJSONValueObjectGetBoolean(entry, "unicast-overflow", &fil->unicast.overflow) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing or invalid 'unicast-overflow' " "in query-rx-filter response")); - goto cleanup; + return -1; } if ((!(table = virJSONValueObjectGet(entry, "unicast-table"))) || (!virJSONValueIsArray(table))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing or invalid 'unicast-table' array " "in query-rx-filter response")); - goto cleanup; + return -1; } nTable = virJSONValueArraySize(table); fil->unicast.table = g_new0(virMacAddr, nTable); @@ -4035,13 +3922,13 @@ qemuMonitorJSONQueryRxFilterParse(virJSONValue *msg, virReportError(VIR_ERR_INTERNAL_ERROR, _("Missing or invalid element %zu of 'unicast' " "list in query-rx-filter response"), i); - goto cleanup; + return -1; } if (virMacAddrParse(tmp, &fil->unicast.table[i]) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("invalid mac address '%s' in 'unicast-table' " "array in query-rx-filter response"), tmp); - goto cleanup; + return -1; } } fil->unicast.nTable = nTable; @@ -4052,21 +3939,21 @@ qemuMonitorJSONQueryRxFilterParse(virJSONValue *msg, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing or invalid 'multicast' " "in query-rx-filter response")); - goto cleanup; + return -1; } if (virJSONValueObjectGetBoolean(entry, "multicast-overflow", &fil->multicast.overflow) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing or invalid 'multicast-overflow' " "in query-rx-filter response")); - goto cleanup; + return -1; } if ((!(table = virJSONValueObjectGet(entry, "multicast-table"))) || (!virJSONValueIsArray(table))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing or invalid 'multicast-table' array " "in query-rx-filter response")); - goto cleanup; + return -1; } nTable = virJSONValueArraySize(table); fil->multicast.table = g_new0(virMacAddr, nTable); @@ -4076,13 +3963,13 @@ qemuMonitorJSONQueryRxFilterParse(virJSONValue *msg, virReportError(VIR_ERR_INTERNAL_ERROR, _("Missing or invalid element %zu of 'multicast' " "list in query-rx-filter response"), i); - goto cleanup; + return -1; } if (virMacAddrParse(tmp, &fil->multicast.table[i]) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("invalid mac address '%s' in 'multicast-table' " "array in query-rx-filter response"), tmp); - goto cleanup; + return -1; } } fil->multicast.nTable = nTable; @@ -4093,14 +3980,14 @@ qemuMonitorJSONQueryRxFilterParse(virJSONValue *msg, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing or invalid 'vlan' " "in query-rx-filter response")); - goto cleanup; + return -1; } if ((!(table = virJSONValueObjectGet(entry, "vlan-table"))) || (!virJSONValueIsArray(table))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing or invalid 'vlan-table' array " "in query-rx-filter response")); - goto cleanup; + return -1; } nTable = virJSONValueArraySize(table); fil->vlan.table = g_new0(unsigned int, nTable); @@ -4110,15 +3997,13 @@ qemuMonitorJSONQueryRxFilterParse(virJSONValue *msg, virReportError(VIR_ERR_INTERNAL_ERROR, _("Missing or invalid element %zu of 'vlan-table' " "array in query-rx-filter response"), i); - goto cleanup; + return -1; } } fil->vlan.nTable = nTable; *filter = g_steal_pointer(&fil); - ret = 0; - cleanup: - return ret; + return 0; } @@ -4126,27 +4011,24 @@ int qemuMonitorJSONQueryRxFilter(qemuMonitor *mon, const char *alias, virNetDevRxFilter **filter) { - int ret = -1; g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("query-rx-filter", "s:name", alias, NULL); g_autoptr(virJSONValue) reply = NULL; if (!cmd) - goto cleanup; + 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; if (qemuMonitorJSONQueryRxFilterParse(reply, filter) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } @@ -4233,7 +4115,6 @@ qemuMonitorJSONGetChardevInfo(qemuMonitor *mon, GHashTable *info) { - int ret = -1; g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("query-chardev", NULL); g_autoptr(virJSONValue) reply = NULL; @@ -4242,21 +4123,18 @@ qemuMonitorJSONGetChardevInfo(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; - ret = qemuMonitorJSONExtractChardevInfo(reply, info); - cleanup: - return ret; + return qemuMonitorJSONExtractChardevInfo(reply, info); } int qemuMonitorJSONDelDevice(qemuMonitor *mon, const char *devalias) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; @@ -4267,19 +4145,15 @@ int qemuMonitorJSONDelDevice(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; - if (qemuMonitorJSONHasError(reply, "DeviceNotFound")) { - ret = -2; - goto cleanup; - } + if (qemuMonitorJSONHasError(reply, "DeviceNotFound")) + return -2; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } @@ -4425,7 +4299,6 @@ qemuMonitorJSONBlockdevMirror(qemuMonitor *mon, int qemuMonitorJSONTransaction(qemuMonitor *mon, virJSONValue **actions) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; @@ -4433,17 +4306,15 @@ qemuMonitorJSONTransaction(qemuMonitor *mon, virJSONValue **actions) "a:actions", actions, NULL); if (!cmd) - goto cleanup; + return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } @@ -4461,7 +4332,6 @@ qemuMonitorJSONBlockCommit(qemuMonitor *mon, const char *backingName, unsigned long long speed) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; virTristateBool autofinalize = VIR_TRISTATE_BOOL_ABSENT; @@ -4488,14 +4358,12 @@ qemuMonitorJSONBlockCommit(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } @@ -4538,7 +4406,6 @@ qemuMonitorJSONDiskNameLookup(qemuMonitor *mon, virStorageSource *top, virStorageSource *target) { - char *ret = NULL; g_autoptr(virJSONValue) devices = NULL; size_t i; @@ -4552,28 +4419,27 @@ qemuMonitorJSONDiskNameLookup(qemuMonitor *mon, const char *thisdev; if (!(dev = qemuMonitorJSONGetBlockDev(devices, i))) - goto cleanup; + return NULL; if (!(thisdev = qemuMonitorJSONGetBlockDevDevice(dev))) - goto cleanup; + return NULL; if (STREQ(thisdev, device)) { if ((inserted = virJSONValueObjectGetObject(dev, "inserted")) && (image = virJSONValueObjectGetObject(inserted, "image"))) { - ret = qemuMonitorJSONDiskNameLookupOne(image, top, target); + return qemuMonitorJSONDiskNameLookupOne(image, top, target); } - break; } } /* Guarantee an error when returning NULL, but don't override a * more specific error if one was already generated. */ - if (!ret && virGetLastErrorCode() == VIR_ERR_OK) + if (virGetLastErrorCode() == VIR_ERR_OK) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to find backing name for device %s"), device); + } - cleanup: - return ret; + return NULL; } @@ -4583,26 +4449,21 @@ int qemuMonitorJSONArbitraryCommand(qemuMonitor *mon, { g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; - int ret = -1; if (!(cmd = virJSONValueFromString(cmd_str))) - goto cleanup; + return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (!(*reply_str = virJSONValueToString(reply, false))) - goto cleanup; + return -1; - ret = 0; - - cleanup: - return ret; + return 0; } int qemuMonitorJSONInjectNMI(qemuMonitor *mon) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; @@ -4611,14 +4472,12 @@ int qemuMonitorJSONInjectNMI(qemuMonitor *mon) return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } int qemuMonitorJSONSendKey(qemuMonitor *mon, @@ -4626,7 +4485,6 @@ int qemuMonitorJSONSendKey(qemuMonitor *mon, unsigned int *keycodes, unsigned int nkeycodes) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; g_autoptr(virJSONValue) keys = NULL; @@ -4641,7 +4499,7 @@ int qemuMonitorJSONSendKey(qemuMonitor *mon, if (keycodes[i] > 0xffff) { virReportError(VIR_ERR_OPERATION_FAILED, _("keycode %zu is invalid: 0x%X"), i, keycodes[i]); - goto cleanup; + return -1; } /* create single key object */ @@ -4649,14 +4507,14 @@ int qemuMonitorJSONSendKey(qemuMonitor *mon, /* Union KeyValue has two types, use the generic one */ if (virJSONValueObjectAppendString(key, "type", "number") < 0) - goto cleanup; + return -1; /* with the keycode */ if (virJSONValueObjectAppendNumberInt(key, "data", keycodes[i]) < 0) - goto cleanup; + return -1; if (virJSONValueArrayAppend(keys, &key) < 0) - goto cleanup; + return -1; } cmd = qemuMonitorJSONMakeCommand("send-key", @@ -4664,17 +4522,15 @@ int qemuMonitorJSONSendKey(qemuMonitor *mon, "p:hold-time", holdtime, NULL); if (!cmd) - goto cleanup; + return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } int qemuMonitorJSONScreendump(qemuMonitor *mon, @@ -4682,7 +4538,6 @@ int qemuMonitorJSONScreendump(qemuMonitor *mon, unsigned int head, const char *file) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; @@ -4696,14 +4551,12 @@ int qemuMonitorJSONScreendump(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } @@ -4841,7 +4694,6 @@ qemuMonitorJSONBlockStream(qemuMonitor *mon, const char *backingName, unsigned long long speed) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; virTristateBool autofinalize = VIR_TRISTATE_BOOL_ABSENT; @@ -4865,15 +4717,12 @@ qemuMonitorJSONBlockStream(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - - cleanup: - return ret; + return 0; } @@ -4906,7 +4755,6 @@ qemuMonitorJSONBlockJobSetSpeed(qemuMonitor *mon, const char *jobname, unsigned long long speed) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; @@ -4917,15 +4765,12 @@ qemuMonitorJSONBlockJobSetSpeed(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONBlockJobError(cmd, reply, jobname) < 0) - goto cleanup; + return -1; - ret = 0; - - cleanup: - return ret; + return 0; } @@ -4933,7 +4778,6 @@ int qemuMonitorJSONDrivePivot(qemuMonitor *mon, const char *jobname) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; @@ -4944,14 +4788,12 @@ qemuMonitorJSONDrivePivot(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONBlockJobError(cmd, reply, jobname) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } @@ -5004,7 +4846,6 @@ int qemuMonitorJSONOpenGraphics(qemuMonitor *mon, const char *fdname, bool skipauth) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; @@ -5018,14 +4859,12 @@ int qemuMonitorJSONOpenGraphics(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } @@ -5174,19 +5013,16 @@ int qemuMonitorJSONGetBlockIoThrottle(qemuMonitor *mon, const char *qdevid, virDomainBlockIoTuneInfo *reply) { - int ret = -1; g_autoptr(virJSONValue) devices = NULL; if (!(devices = qemuMonitorJSONQueryBlock(mon))) return -1; - ret = qemuMonitorJSONBlockIoThrottleInfo(devices, drivealias, qdevid, reply); - return ret; + return qemuMonitorJSONBlockIoThrottleInfo(devices, drivealias, qdevid, reply); } int qemuMonitorJSONSystemWakeup(qemuMonitor *mon) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; @@ -5195,14 +5031,12 @@ int qemuMonitorJSONSystemWakeup(qemuMonitor *mon) return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } int qemuMonitorJSONGetVersion(qemuMonitor *mon, @@ -5211,7 +5045,6 @@ int qemuMonitorJSONGetVersion(qemuMonitor *mon, int *micro, char **package) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; virJSONValue *data; @@ -5225,33 +5058,33 @@ int qemuMonitorJSONGetVersion(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) - goto cleanup; + return -1; data = virJSONValueObjectGetObject(reply, "return"); if (!(qemu = virJSONValueObjectGetObject(data, "qemu"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("query-version reply was missing 'qemu' data")); - goto cleanup; + return -1; } if (virJSONValueObjectGetNumberInt(qemu, "major", major) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("query-version reply was missing 'major' version")); - goto cleanup; + return -1; } if (virJSONValueObjectGetNumberInt(qemu, "minor", minor) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("query-version reply was missing 'minor' version")); - goto cleanup; + return -1; } if (virJSONValueObjectGetNumberInt(qemu, "micro", micro) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("query-version reply was missing 'micro' version")); - goto cleanup; + return -1; } if (package) { @@ -5259,15 +5092,12 @@ int qemuMonitorJSONGetVersion(qemuMonitor *mon, if (!(tmp = virJSONValueObjectGetString(data, "package"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("query-version reply was missing 'package' version")); - goto cleanup; + return -1; } *package = g_strdup(tmp); } - ret = 0; - - cleanup: - return ret; + return 0; } @@ -5593,7 +5423,6 @@ qemuMonitorJSONParseCPUModel(const char *cpu_name, qemuMonitorCPUModelInfo **model_info) { g_autoptr(qemuMonitorCPUModelInfo) machine_model = NULL; - int ret = -1; machine_model = g_new0(qemuMonitorCPUModelInfo, 1); machine_model->name = g_strdup(cpu_name); @@ -5606,14 +5435,11 @@ qemuMonitorJSONParseCPUModel(const char *cpu_name, if (virJSONValueObjectForeachKeyValue(cpu_props, qemuMonitorJSONParseCPUModelProperty, machine_model) < 0) - goto cleanup; + return -1; } *model_info = g_steal_pointer(&machine_model); - ret = 0; - - cleanup: - return ret; + return 0; } @@ -5876,7 +5702,6 @@ int qemuMonitorJSONGetKVMState(qemuMonitor *mon, bool *enabled, bool *present) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; virJSONValue *data = NULL; @@ -5888,10 +5713,10 @@ int qemuMonitorJSONGetKVMState(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) - goto cleanup; + return -1; data = virJSONValueObjectGetObject(reply, "return"); @@ -5899,13 +5724,10 @@ int qemuMonitorJSONGetKVMState(qemuMonitor *mon, virJSONValueObjectGetBoolean(data, "present", present) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("query-kvm replied unexpected data")); - goto cleanup; + return -1; } - ret = 0; - - cleanup: - return ret; + return 0; } @@ -6053,10 +5875,10 @@ int qemuMonitorJSONGetObjectProperty(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; data = virJSONValueObjectGet(reply, "return"); @@ -6093,19 +5915,17 @@ int qemuMonitorJSONGetObjectProperty(qemuMonitor *mon, virReportError(VIR_ERR_INTERNAL_ERROR, _("qom-get invalid object property type %d"), prop->type); - goto cleanup; + return -1; break; } if (ret == -1) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("qom-get reply was missing return data")); - goto cleanup; + return -1; } - ret = 0; - cleanup: - return ret; + return 0; } @@ -6150,7 +5970,6 @@ int qemuMonitorJSONSetObjectProperty(qemuMonitor *mon, const char *property, qemuMonitorJSONObjectProperty *prop) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; @@ -6183,21 +6002,19 @@ int qemuMonitorJSONSetObjectProperty(qemuMonitor *mon, virReportError(VIR_ERR_INTERNAL_ERROR, _("qom-set invalid object property type %d"), prop->type); - goto cleanup; + return -1; } if (!cmd) return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } #undef MAKE_SET_CMD @@ -6326,7 +6143,6 @@ qemuMonitorJSONGetObjectProps(qemuMonitor *mon, char * qemuMonitorJSONGetTargetArch(qemuMonitor *mon) { - char *ret = NULL; const char *arch; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; @@ -6336,23 +6152,20 @@ qemuMonitorJSONGetTargetArch(qemuMonitor *mon) return NULL; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return NULL; if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) - goto cleanup; + return NULL; data = virJSONValueObjectGetObject(reply, "return"); if (!(arch = virJSONValueObjectGetString(data, "arch"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("query-target reply was missing arch data")); - goto cleanup; + return NULL; } - ret = g_strdup(arch); - - cleanup: - return ret; + return g_strdup(arch); } @@ -6449,7 +6262,6 @@ int qemuMonitorJSONGetGICCapabilities(qemuMonitor *mon, virGICCapability **capabilities) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; virJSONValue *caps; @@ -6464,27 +6276,23 @@ qemuMonitorJSONGetGICCapabilities(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; /* If the 'query-gic-capabilities' QMP command was not available * we simply successfully return zero capabilities. * This is the case for QEMU <2.6 and all non-ARM architectures */ - if (qemuMonitorJSONHasError(reply, "CommandNotFound")) { - ret = 0; - goto cleanup; - } + if (qemuMonitorJSONHasError(reply, "CommandNotFound")) + return 0; if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) - goto cleanup; + return -1; caps = virJSONValueObjectGetArray(reply, "return"); n = virJSONValueArraySize(caps); /* If the returned array was empty we have to return successfully */ - if (n == 0) { - ret = 0; - goto cleanup; - } + if (n == 0) + return 0; list = g_new0(virGICCapability, n); @@ -6497,25 +6305,25 @@ qemuMonitorJSONGetGICCapabilities(qemuMonitor *mon, if (!cap || virJSONValueGetType(cap) != VIR_JSON_TYPE_OBJECT) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing entry in GIC capabilities list")); - goto cleanup; + return -1; } if (virJSONValueObjectGetNumberInt(cap, "version", &version) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing GIC version")); - goto cleanup; + return -1; } if (virJSONValueObjectGetBoolean(cap, "kernel", &kernel) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing in-kernel GIC information")); - goto cleanup; + return -1; } if (virJSONValueObjectGetBoolean(cap, "emulated", &emulated) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing emulated GIC information")); - goto cleanup; + return -1; } list[i].version = version; @@ -6525,11 +6333,8 @@ qemuMonitorJSONGetGICCapabilities(qemuMonitor *mon, list[i].implementation |= VIR_GIC_IMPLEMENTATION_EMULATED; } - ret = n; *capabilities = g_steal_pointer(&list); - - cleanup: - return ret; + return n; } @@ -6551,7 +6356,6 @@ int qemuMonitorJSONGetSEVCapabilities(qemuMonitor *mon, virSEVCapability **capabilities) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; virJSONValue *caps; @@ -6568,16 +6372,14 @@ qemuMonitorJSONGetSEVCapabilities(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; /* QEMU has only compiled-in support of SEV */ - if (qemuMonitorJSONHasError(reply, "GenericError")) { - ret = 0; - goto cleanup; - } + if (qemuMonitorJSONHasError(reply, "GenericError")) + return 0; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; caps = virJSONValueObjectGetObject(reply, "return"); @@ -6585,7 +6387,7 @@ qemuMonitorJSONGetSEVCapabilities(qemuMonitor *mon, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("query-sev-capabilities reply was missing" " 'cbitpos' field")); - goto cleanup; + return -1; } if (virJSONValueObjectGetNumberUint(caps, "reduced-phys-bits", @@ -6593,21 +6395,21 @@ qemuMonitorJSONGetSEVCapabilities(qemuMonitor *mon, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("query-sev-capabilities reply was missing" " 'reduced-phys-bits' field")); - goto cleanup; + return -1; } if (!(pdh = virJSONValueObjectGetString(caps, "pdh"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("query-sev-capabilities reply was missing" " 'pdh' field")); - goto cleanup; + return -1; } if (!(cert_chain = virJSONValueObjectGetString(caps, "cert-chain"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("query-sev-capabilities reply was missing" " 'cert-chain' field")); - goto cleanup; + return -1; } capability = g_new0(virSEVCapability, 1); @@ -6619,9 +6421,7 @@ qemuMonitorJSONGetSEVCapabilities(qemuMonitor *mon, capability->cbitpos = cbitpos; capability->reduced_phys_bits = reduced_phys_bits; *capabilities = g_steal_pointer(&capability); - ret = 1; - cleanup: - return ret; + return 1; } static virJSONValue * @@ -6663,7 +6463,6 @@ qemuMonitorJSONNBDServerStart(qemuMonitor *mon, const virStorageNetHostDef *server, const char *tls_alias) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; g_autoptr(virJSONValue) addr = NULL; @@ -6681,27 +6480,24 @@ qemuMonitorJSONNBDServerStart(qemuMonitor *mon, case VIR_STORAGE_NET_HOST_TRANS_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("invalid server address")); - goto cleanup; + return -1; } if (!addr) - goto cleanup; + return -1; if (!(cmd = qemuMonitorJSONMakeCommand("nbd-server-start", "a:addr", &addr, "S:tls-creds", tls_alias, NULL))) - goto cleanup; + return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - - cleanup: - return ret; + return 0; } int @@ -6711,7 +6507,6 @@ qemuMonitorJSONNBDServerAdd(qemuMonitor *mon, bool writable, const char *bitmap) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; @@ -6722,39 +6517,34 @@ qemuMonitorJSONNBDServerAdd(qemuMonitor *mon, "b:writable", writable, "S:bitmap", bitmap, NULL))) - return ret; + return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } int qemuMonitorJSONNBDServerStop(qemuMonitor *mon) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; if (!(cmd = qemuMonitorJSONMakeCommand("nbd-server-stop", NULL))) - return ret; + return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } @@ -6833,7 +6623,6 @@ static virJSONValue * qemuMonitorJSONAttachCharDevCommand(const char *chrID, const virDomainChrSourceDef *chr) { - virJSONValue *ret = NULL; g_autoptr(virJSONValue) backend = virJSONValueNewObject(); g_autoptr(virJSONValue) data = virJSONValueNewObject(); g_autoptr(virJSONValue) addr = NULL; @@ -6859,18 +6648,18 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, case VIR_DOMAIN_CHR_TYPE_FILE: backend_type = "file"; if (virJSONValueObjectAppendString(data, "out", chr->data.file.path) < 0) - goto cleanup; + return NULL; if (virJSONValueObjectAdd(data, "T:append", chr->data.file.append, NULL) < 0) - goto cleanup; + return NULL; break; case VIR_DOMAIN_CHR_TYPE_DEV: backend_type = STRPREFIX(chrID, "parallel") ? "parallel" : "serial"; if (virJSONValueObjectAppendString(data, "device", chr->data.file.path) < 0) - goto cleanup; + return NULL; break; case VIR_DOMAIN_CHR_TYPE_TCP: @@ -6879,27 +6668,27 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, chr->data.tcp.service); if (!addr || virJSONValueObjectAppend(data, "addr", &addr) < 0) - goto cleanup; + return NULL; telnet = chr->data.tcp.protocol == VIR_DOMAIN_CHR_TCP_PROTOCOL_TELNET; if (chr->data.tcp.listen && virJSONValueObjectAppendBoolean(data, "wait", false) < 0) - goto cleanup; + return NULL; if (virJSONValueObjectAppendBoolean(data, "telnet", telnet) < 0 || virJSONValueObjectAppendBoolean(data, "server", chr->data.tcp.listen) < 0) - goto cleanup; + return NULL; if (chr->data.tcp.tlscreds) { if (!(tlsalias = qemuAliasTLSObjFromSrcAlias(chrID))) - goto cleanup; + return NULL; if (virJSONValueObjectAppendString(data, "tls-creds", tlsalias) < 0) - goto cleanup; + return NULL; } if (qemuMonitorJSONBuildChrChardevReconnect(data, &chr->data.tcp.reconnect) < 0) - goto cleanup; + return NULL; break; case VIR_DOMAIN_CHR_TYPE_UDP: @@ -6911,7 +6700,7 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, chr->data.udp.connectService); if (!addr || virJSONValueObjectAppend(data, "remote", &addr) < 0) - goto cleanup; + return NULL; host = chr->data.udp.bindHost; port = chr->data.udp.bindService; @@ -6923,7 +6712,7 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, addr = qemuMonitorJSONBuildInetSocketAddress(host, port); if (!addr || virJSONValueObjectAppend(data, "local", &addr) < 0) - goto cleanup; + return NULL; } break; @@ -6933,17 +6722,17 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, if (!addr || virJSONValueObjectAppend(data, "addr", &addr) < 0) - goto cleanup; + return NULL; if (chr->data.nix.listen && virJSONValueObjectAppendBoolean(data, "wait", false) < 0) - goto cleanup; + return NULL; if (virJSONValueObjectAppendBoolean(data, "server", chr->data.nix.listen) < 0) - goto cleanup; + return NULL; if (qemuMonitorJSONBuildChrChardevReconnect(data, &chr->data.nix.reconnect) < 0) - goto cleanup; + return NULL; break; case VIR_DOMAIN_CHR_TYPE_SPICEVMC: @@ -6951,7 +6740,7 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, if (virJSONValueObjectAppendString(data, "type", virDomainChrSpicevmcTypeToString(chr->data.spicevmc)) < 0) - goto cleanup; + return NULL; break; case VIR_DOMAIN_CHR_TYPE_SPICEPORT: @@ -6968,7 +6757,7 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, _("Hotplug unsupported for char device type '%d'"), chr->type); } - goto cleanup; + return NULL; } if (chr->logfile && @@ -6976,20 +6765,16 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, "s:logfile", chr->logfile, "T:logappend", chr->logappend, NULL) < 0) - goto cleanup; + return NULL; if (virJSONValueObjectAppendString(backend, "type", backend_type) < 0 || virJSONValueObjectAppend(backend, "data", &data) < 0) - goto cleanup; + return NULL; - if (!(ret = qemuMonitorJSONMakeCommand("chardev-add", - "s:id", chrID, - "a:backend", &backend, - NULL))) - goto cleanup; - - cleanup: - return ret; + return qemuMonitorJSONMakeCommand("chardev-add", + "s:id", chrID, + "a:backend", &backend, + NULL); } @@ -6998,22 +6783,21 @@ qemuMonitorJSONAttachCharDev(qemuMonitor *mon, const char *chrID, virDomainChrSourceDef *chr) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; if (!(cmd = qemuMonitorJSONAttachCharDevCommand(chrID, chr))) - return ret; + return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (chr->type == VIR_DOMAIN_CHR_TYPE_PTY) { if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) - goto cleanup; + return -1; } else { if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; } if (chr->type == VIR_DOMAIN_CHR_TYPE_PTY) { @@ -7023,40 +6807,34 @@ qemuMonitorJSONAttachCharDev(qemuMonitor *mon, if (!(path = virJSONValueObjectGetString(data, "pty"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("chardev-add reply was missing pty path")); - goto cleanup; + return -1; } chr->data.file.path = g_strdup(path); } - ret = 0; - - cleanup: - return ret; + return 0; } int qemuMonitorJSONDetachCharDev(qemuMonitor *mon, const char *chrID) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; if (!(cmd = qemuMonitorJSONMakeCommand("chardev-remove", "s:id", chrID, NULL))) - return ret; + return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } @@ -7177,28 +6955,24 @@ qemuMonitorJSONGetCPUx86Data(qemuMonitor *mon, g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; virJSONValue *data; - int ret = -1; if (!(cmd = qemuMonitorJSONMakeCommand("qom-get", "s:path", QOM_CPU_PATH, "s:property", property, NULL))) - goto cleanup; + 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"); if (!(*cpudata = qemuMonitorJSONParseCPUx86Features(data))) - goto cleanup; + return -1; - ret = 0; - - cleanup: - return ret; + return 0; } @@ -7214,27 +6988,25 @@ qemuMonitorJSONCheckCPUx86(qemuMonitor *mon) virJSONValue *data; size_t i; size_t n; - int ret = -1; if (!(cmd = qemuMonitorJSONMakeCommand("qom-list", "s:path", QOM_CPU_PATH, NULL))) - goto cleanup; + return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if ((data = virJSONValueObjectGet(reply, "error"))) { const char *klass = virJSONValueObjectGetString(data, "class"); if (STREQ_NULLABLE(klass, "DeviceNotFound") || STREQ_NULLABLE(klass, "CommandNotFound")) { - ret = 0; - goto cleanup; + return 0; } } if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) - goto cleanup; + return -1; data = virJSONValueObjectGetArray(reply, "return"); n = virJSONValueArraySize(data); @@ -7243,16 +7015,10 @@ qemuMonitorJSONCheckCPUx86(qemuMonitor *mon) virJSONValue *element = virJSONValueArrayGet(data, i); if (STREQ_NULLABLE(virJSONValueObjectGetString(element, "name"), "feature-words")) - break; + return 1; } - if (i == n) - ret = 0; - else - ret = 1; - - cleanup: - return ret; + return 0; } @@ -7408,50 +7174,43 @@ qemuMonitorJSONGetGuestCPU(qemuMonitor *mon, { g_autoptr(virCPUData) cpuEnabled = NULL; g_autoptr(virCPUData) cpuDisabled = NULL; - int ret = -1; if (!(cpuEnabled = virCPUDataNew(arch)) || !(cpuDisabled = virCPUDataNew(arch))) - goto cleanup; + return -1; if (qemuMonitorJSONGetCPUData(mon, translate, opaque, cpuEnabled) < 0) - goto cleanup; + return -1; if (disabled && qemuMonitorJSONGetCPUDataDisabled(mon, translate, opaque, cpuDisabled) < 0) - goto cleanup; + return -1; *enabled = g_steal_pointer(&cpuEnabled); if (disabled) *disabled = g_steal_pointer(&cpuDisabled); - ret = 0; - - cleanup: - return ret; + return 0; } int qemuMonitorJSONRTCResetReinjection(qemuMonitor *mon) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; if (!(cmd = qemuMonitorJSONMakeCommand("rtc-reset-reinjection", NULL))) - return ret; + return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - return ret; + return 0; } /** @@ -7558,7 +7317,6 @@ int qemuMonitorJSONSetIOThread(qemuMonitor *mon, qemuMonitorIOThreadInfo *iothreadInfo) { - int ret = -1; g_autofree char *path = NULL; qemuMonitorJSONObjectProperty prop; @@ -7570,7 +7328,7 @@ qemuMonitorJSONSetIOThread(qemuMonitor *mon, prop.type = QEMU_MONITOR_OBJECT_PROPERTY_INT; \ prop.val.iv = iothreadInfo->propVal; \ if (qemuMonitorJSONSetObjectProperty(mon, path, propName, &prop) < 0) \ - goto cleanup; \ + return -1; \ } VIR_IOTHREAD_SET_PROP("poll-max-ns", poll_max_ns); @@ -7579,10 +7337,7 @@ qemuMonitorJSONSetIOThread(qemuMonitor *mon, #undef VIR_IOTHREAD_SET_PROP - ret = 0; - - cleanup: - return ret; + return 0; } @@ -7590,7 +7345,6 @@ int qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon, GHashTable *info) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; virJSONValue *data = NULL; @@ -7600,10 +7354,10 @@ qemuMonitorJSONGetMemoryDeviceInfo(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"); @@ -7618,14 +7372,14 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("query-memory-devices reply data doesn't contain " "enum type discriminator")); - goto cleanup; + return -1; } if (!(dimminfo = virJSONValueObjectGetObject(elem, "data"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("query-memory-devices reply data doesn't " "contain enum data")); - goto cleanup; + return -1; } /* While 'id' attribute is marked as optional in QEMU's QAPI @@ -7634,7 +7388,7 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon, if (!(devalias = virJSONValueObjectGetString(dimminfo, "id"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("dimm memory info data is missing 'id'")); - goto cleanup; + return -1; } meminfo = g_new0(qemuMonitorMemoryDeviceInfo, 1); @@ -7645,21 +7399,21 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon, &meminfo->address) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed/missing addr in dimm memory info")); - goto cleanup; + return -1; } if (virJSONValueObjectGetNumberUint(dimminfo, "slot", &meminfo->slot) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed/missing slot in dimm memory info")); - goto cleanup; + return -1; } if (virJSONValueObjectGetBoolean(dimminfo, "hotplugged", &meminfo->hotplugged) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed/missing hotplugged in dimm memory info")); - goto cleanup; + return -1; } @@ -7667,7 +7421,7 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon, &meminfo->hotpluggable) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed/missing hotpluggable in dimm memory info")); - goto cleanup; + return -1; } @@ -7676,7 +7430,7 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon, &meminfo->size) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed/missing size in virtio memory info")); - goto cleanup; + return -1; } } else { /* type not handled yet */ @@ -7684,15 +7438,12 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitor *mon, } if (virHashAddEntry(info, devalias, meminfo) < 0) - goto cleanup; + return -1; meminfo = NULL; } - ret = 0; - - cleanup: - return ret; + return 0; } @@ -7855,7 +7606,6 @@ qemuMonitorJSONMigrateIncoming(qemuMonitor *mon, int qemuMonitorJSONMigrateStartPostCopy(qemuMonitor *mon) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; @@ -7863,12 +7613,9 @@ qemuMonitorJSONMigrateStartPostCopy(qemuMonitor *mon) return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; - ret = qemuMonitorJSONCheckError(cmd, reply); - - cleanup: - return ret; + return qemuMonitorJSONCheckError(cmd, reply); } @@ -7877,7 +7624,6 @@ qemuMonitorJSONMigrateContinue(qemuMonitor *mon, qemuMonitorMigrationStatus status) { const char *statusStr = qemuMonitorMigrationStatusTypeToString(status); - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; @@ -7887,12 +7633,9 @@ qemuMonitorJSONMigrateContinue(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; - ret = qemuMonitorJSONCheckError(cmd, reply); - - cleanup: - return ret; + return qemuMonitorJSONCheckError(cmd, reply); } @@ -7900,7 +7643,6 @@ int qemuMonitorJSONGetRTCTime(qemuMonitor *mon, struct tm *tm) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; virJSONValue *data; @@ -7912,10 +7654,10 @@ qemuMonitorJSONGetRTCTime(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) - goto cleanup; + return -1; data = virJSONValueObjectGet(reply, "return"); @@ -7927,12 +7669,10 @@ qemuMonitorJSONGetRTCTime(qemuMonitor *mon, virJSONValueObjectGetNumberInt(data, "tm_sec", &tm->tm_sec) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("qemu returned malformed time")); - goto cleanup; + return -1; } - ret = 0; - cleanup: - return ret; + return 0; } @@ -8108,21 +7848,17 @@ qemuMonitorJSONQueryQMPSchema(qemuMonitor *mon) { g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; - virJSONValue *ret = NULL; if (!(cmd = qemuMonitorJSONMakeCommand("query-qmp-schema", NULL))) return NULL; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return NULL; if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) - goto cleanup; + return NULL; - ret = virJSONValueObjectStealArray(reply, "return"); - - cleanup: - return ret; + return virJSONValueObjectStealArray(reply, "return"); } @@ -8133,7 +7869,6 @@ qemuMonitorJSONSetBlockThreshold(qemuMonitor *mon, { g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; - int ret = -1; if (!(cmd = qemuMonitorJSONMakeCommand("block-set-write-threshold", "s:node-name", nodename, @@ -8142,15 +7877,12 @@ qemuMonitorJSONSetBlockThreshold(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - - cleanup: - return ret; + return 0; } @@ -8293,7 +8025,6 @@ qemuMonitorJSONBlockdevTrayOpen(qemuMonitor *mon, { g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; - int ret = -1; if (!(cmd = qemuMonitorJSONMakeCommand("blockdev-open-tray", "s:id", id, @@ -8301,15 +8032,12 @@ qemuMonitorJSONBlockdevTrayOpen(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - - cleanup: - return ret; + return 0; } @@ -8319,22 +8047,18 @@ qemuMonitorJSONBlockdevTrayClose(qemuMonitor *mon, { g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; - int ret = -1; if (!(cmd = qemuMonitorJSONMakeCommand("blockdev-close-tray", "s:id", id, NULL))) return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - - cleanup: - return ret; + return 0; } @@ -8344,22 +8068,18 @@ qemuMonitorJSONBlockdevMediumRemove(qemuMonitor *mon, { g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; - int ret = -1; if (!(cmd = qemuMonitorJSONMakeCommand("blockdev-remove-medium", "s:id", id, NULL))) return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - - cleanup: - return ret; + return 0; } @@ -8370,7 +8090,6 @@ qemuMonitorJSONBlockdevMediumInsert(qemuMonitor *mon, { g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; - int ret = -1; if (!(cmd = qemuMonitorJSONMakeCommand("blockdev-insert-medium", "s:id", id, @@ -8379,15 +8098,12 @@ qemuMonitorJSONBlockdevMediumInsert(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; + return -1; - ret = 0; - - cleanup: - return ret; + return 0; } @@ -8405,7 +8121,6 @@ char * qemuMonitorJSONGetSEVMeasurement(qemuMonitor *mon) { const char *tmp; - char *measurement = NULL; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; virJSONValue *data; @@ -8414,20 +8129,17 @@ qemuMonitorJSONGetSEVMeasurement(qemuMonitor *mon) return NULL; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return NULL; if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) - goto cleanup; + return NULL; data = virJSONValueObjectGetObject(reply, "return"); if (!(tmp = virJSONValueObjectGetString(data, "data"))) - goto cleanup; + return NULL; - measurement = g_strdup(tmp); - - cleanup: - return measurement; + return g_strdup(tmp); } @@ -8443,7 +8155,6 @@ qemuMonitorJSONExtractPRManagerInfo(virJSONValue *reply, GHashTable *info) { virJSONValue *data; - int ret = -1; size_t i; data = virJSONValueObjectGetArray(reply, "return"); @@ -8465,19 +8176,17 @@ qemuMonitorJSONExtractPRManagerInfo(virJSONValue *reply, } if (virHashAddEntry(info, alias, entry) < 0) - goto cleanup; + return -1; entry = NULL; } - ret = 0; - cleanup: - return ret; + return 0; malformed: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed prManager reply")); - goto cleanup; + return -1; } @@ -8485,7 +8194,6 @@ int qemuMonitorJSONGetPRManagerInfo(qemuMonitor *mon, GHashTable *info) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; @@ -8494,15 +8202,12 @@ qemuMonitorJSONGetPRManagerInfo(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; - - ret = qemuMonitorJSONExtractPRManagerInfo(reply, info); - cleanup: - return ret; + return -1; + return qemuMonitorJSONExtractPRManagerInfo(reply, info); } @@ -8533,7 +8238,6 @@ int qemuMonitorJSONGetCurrentMachineInfo(qemuMonitor *mon, qemuMonitorCurrentMachineInfo *info) { - int ret = -1; g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) reply = NULL; @@ -8542,15 +8246,12 @@ qemuMonitorJSONGetCurrentMachineInfo(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) - goto cleanup; + return -1; - ret = qemuMonitorJSONExtractCurrentMachineInfo(reply, info); - - cleanup: - return ret; + return qemuMonitorJSONExtractCurrentMachineInfo(reply, info); } -- 2.32.0

After previous cleanups, some 'error' labels were rendered needless - they contain nothing more than a return statement. Well, those labels can be dropped and 'goto error' can be replaced with return statement directly. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_monitor_json.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index bb76ac7d37..e9be9bdabd 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -5351,7 +5351,7 @@ qemuMonitorJSONMakeCPUModel(virCPUDef *cpu, size_t i; if (virJSONValueObjectAppendString(model, "name", cpu->model) < 0) - goto error; + return NULL; if (cpu->nfeatures || !migratable) { g_autoptr(virJSONValue) props = virJSONValueNewObject(); @@ -5367,22 +5367,19 @@ qemuMonitorJSONMakeCPUModel(virCPUDef *cpu, enabled = true; if (virJSONValueObjectAppendBoolean(props, name, enabled) < 0) - goto error; + return NULL; } if (!migratable && virJSONValueObjectAppendBoolean(props, "migratable", false) < 0) { - goto error; + return NULL; } if (virJSONValueObjectAppend(model, "props", &props) < 0) - goto error; + return NULL; } return g_steal_pointer(&model); - - error: - return NULL; } @@ -6930,20 +6927,17 @@ qemuMonitorJSONParseCPUx86Features(virJSONValue *data) size_t i; if (!(cpudata = virCPUDataNew(VIR_ARCH_X86_64))) - goto error; + return NULL; item.type = VIR_CPU_X86_DATA_CPUID; for (i = 0; i < virJSONValueArraySize(data); i++) { if (qemuMonitorJSONParseCPUx86FeatureWord(virJSONValueArrayGet(data, i), &item.data.cpuid) < 0 || virCPUx86DataAdd(cpudata, &item) < 0) - goto error; + return NULL; } return g_steal_pointer(&cpudata); - - error: - return NULL; } @@ -7049,20 +7043,17 @@ qemuMonitorJSONGetGuestCPUx86(qemuMonitor *mon, if (qemuMonitorJSONGetCPUx86Data(mon, "feature-words", &cpuEnabled) < 0) - goto error; + return -1; if (disabled && qemuMonitorJSONGetCPUx86Data(mon, "filtered-features", &cpuDisabled) < 0) - goto error; + return -1; *data = g_steal_pointer(&cpuEnabled); if (disabled) *disabled = g_steal_pointer(&cpuDisabled); return 0; - - error: - return -1; } -- 2.32.0

On Mon, 2021-10-25 at 12:57 +0200, Michal Privoznik wrote:
*** BLURB HERE ***
Michal Prívozník (13): qemu_monitor_json: Don't check for qemuMonitorNextCommandID() retval qemu_monitor_json: Don't transfer ownership to @msg qemuMonitorJSONHumanCommand: Require @reply_str qemuMonitorJSONGetMigrationStats: Don't clear @stats on failure qemuMonitorJSONQueryRxFilterParse: Set *filter only on success qemu_monitor: Declare and use g_autoptr for qemuMonitorEventPanicInfo qemu_monitor_json: Use g_autoptr() for virCPUData qemu_monitor_json: Use g_autoptr() for qemuMonitorCPUModelInfo qemuMonitorJSONExtractPRManagerInfo: Declare @entry inside the loop qemu_monitor_json: Use g_autoptr() for virJSONValue qemu_monitor_json: Use g_autofree qemu_monitor_json: Drop pointless cleanup labels qemu_monitor_json: Drop pointless error labels
src/qemu/qemu_monitor.c | 2 +- src/qemu/qemu_monitor.h | 3 +- src/qemu/qemu_monitor_json.c | 1803 ++++++++++++-------------------- -- 3 files changed, 641 insertions(+), 1167 deletions(-)
1167 deletions Thanks!
Reviewed-by: Tim Wiederhake <twiederh@redhat.com> Tim
participants (2)
-
Michal Privoznik
-
Tim Wiederhake