From: Peter Krempa Date: Wed, 18 Mar 2020 09:29:41 +0000 (+0100) Subject: qemuMonitorJSON(Add|Del)Object: Refactor cleanup X-Git-Tag: v6.2.0-rc1~133 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9633dfbcfc8b16d411b52bfab7e743ce466b175a;p=thirdparty%2Flibvirt.git qemuMonitorJSON(Add|Del)Object: Refactor cleanup Use 'g_autoptr' and remove the cleanup label and ret variable. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 8ac8291d0a..00d7760a05 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -4418,51 +4418,39 @@ int qemuMonitorJSONAddObject(qemuMonitorPtr mon, virJSONValuePtr props) { - int ret = -1; - virJSONValuePtr cmd; - virJSONValuePtr reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; if (!(cmd = qemuMonitorJSONMakeCommandInternal("object-add", props))) - 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: - virJSONValueFree(cmd); - virJSONValueFree(reply); - return ret; + return 0; } -int qemuMonitorJSONDelObject(qemuMonitorPtr mon, - const char *objalias) +int +qemuMonitorJSONDelObject(qemuMonitorPtr mon, + const char *objalias) { - int ret = -1; - virJSONValuePtr cmd; - virJSONValuePtr reply = NULL; + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; - cmd = qemuMonitorJSONMakeCommand("object-del", - "s:id", objalias, - NULL); - if (!cmd) + if (!(cmd = qemuMonitorJSONMakeCommand("object-del", "s:id", objalias, 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: - virJSONValueFree(cmd); - virJSONValueFree(reply); - return ret; + return 0; }