mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-24 04:12:20 +00:00
qemuMonitorJSON(Add|Remove)Netdev: Refactor cleanup
Use automatic pointer cleanup for virJSONValuePtrs to get rid of the cleanup label and ret variable. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
973e2d9b9f
commit
eb56a98672
@ -3984,13 +3984,13 @@ int qemuMonitorJSONCloseFileHandle(qemuMonitorPtr mon,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int qemuMonitorJSONAddNetdev(qemuMonitorPtr mon,
|
int
|
||||||
const char *netdevstr)
|
qemuMonitorJSONAddNetdev(qemuMonitorPtr mon,
|
||||||
|
const char *netdevstr)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
g_autoptr(virJSONValue) cmd = NULL;
|
||||||
virJSONValuePtr cmd = NULL;
|
g_autoptr(virJSONValue) reply = NULL;
|
||||||
virJSONValuePtr reply = NULL;
|
g_autoptr(virJSONValue) args = NULL;
|
||||||
virJSONValuePtr args = NULL;
|
|
||||||
|
|
||||||
cmd = qemuMonitorJSONMakeCommand("netdev_add", NULL);
|
cmd = qemuMonitorJSONMakeCommand("netdev_add", NULL);
|
||||||
if (!cmd)
|
if (!cmd)
|
||||||
@ -3998,49 +3998,41 @@ int qemuMonitorJSONAddNetdev(qemuMonitorPtr mon,
|
|||||||
|
|
||||||
args = qemuMonitorJSONKeywordStringToJSON(netdevstr, "type");
|
args = qemuMonitorJSONKeywordStringToJSON(netdevstr, "type");
|
||||||
if (!args)
|
if (!args)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (virJSONValueObjectAppend(cmd, "arguments", args) < 0)
|
if (virJSONValueObjectAppend(cmd, "arguments", args) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
args = NULL; /* obj owns reference to args now */
|
args = NULL; /* obj owns reference to args now */
|
||||||
|
|
||||||
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
cleanup:
|
|
||||||
virJSONValueFree(args);
|
|
||||||
virJSONValueFree(cmd);
|
|
||||||
virJSONValueFree(reply);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int qemuMonitorJSONRemoveNetdev(qemuMonitorPtr mon,
|
int
|
||||||
const char *alias)
|
qemuMonitorJSONRemoveNetdev(qemuMonitorPtr mon,
|
||||||
|
const char *alias)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("netdev_del",
|
||||||
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("netdev_del",
|
"s:id", alias,
|
||||||
"s:id", alias,
|
NULL);
|
||||||
NULL);
|
g_autoptr(virJSONValue) reply = NULL;
|
||||||
virJSONValuePtr reply = NULL;
|
|
||||||
if (!cmd)
|
if (!cmd)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
cleanup:
|
|
||||||
virJSONValueFree(cmd);
|
|
||||||
virJSONValueFree(reply);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user