qemuMonitorJSON(Add|Del)Object: Refactor cleanup

Use 'g_autoptr' and remove the cleanup label and ret variable.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2020-03-18 10:29:41 +01:00
parent 0279754128
commit 9633dfbcfc

View File

@ -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;
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
goto cleanup;
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
goto cleanup;
ret = 0;
cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
}
int qemuMonitorJSONDelObject(qemuMonitorPtr mon,
const char *objalias)
{
int ret = -1;
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
cmd = qemuMonitorJSONMakeCommand("object-del",
"s:id", objalias,
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:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
return 0;
}
int
qemuMonitorJSONDelObject(qemuMonitorPtr mon,
const char *objalias)
{
g_autoptr(virJSONValue) cmd = NULL;
g_autoptr(virJSONValue) reply = NULL;
if (!(cmd = qemuMonitorJSONMakeCommand("object-del", "s:id", objalias, NULL)))
return -1;
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
return -1;
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
return -1;
return 0;
}