mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 14:15:28 +00:00
qemuMigrationParamsToJSON: Refactor variable cleanup
Use automatic memory allocation and move variables into correct scope to simplify the code and remove the need for a 'error:' label. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
f2108c790c
commit
47a9f078f0
@ -718,20 +718,17 @@ qemuMigrationParamsFromJSON(virJSONValuePtr params)
|
|||||||
virJSONValuePtr
|
virJSONValuePtr
|
||||||
qemuMigrationParamsToJSON(qemuMigrationParamsPtr migParams)
|
qemuMigrationParamsToJSON(qemuMigrationParamsPtr migParams)
|
||||||
{
|
{
|
||||||
virJSONValuePtr params = virJSONValueNewObject();
|
g_autoptr(virJSONValue) params = virJSONValueNewObject();
|
||||||
qemuMigrationParamValuePtr pv;
|
|
||||||
const char *name;
|
|
||||||
size_t i;
|
size_t i;
|
||||||
int rc;
|
|
||||||
|
|
||||||
for (i = 0; i < QEMU_MIGRATION_PARAM_LAST; i++) {
|
for (i = 0; i < QEMU_MIGRATION_PARAM_LAST; i++) {
|
||||||
name = qemuMigrationParamTypeToString(i);
|
const char *name = qemuMigrationParamTypeToString(i);
|
||||||
pv = &migParams->params[i];
|
qemuMigrationParamValuePtr pv = &migParams->params[i];
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
if (!pv->set)
|
if (!pv->set)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
rc = 0;
|
|
||||||
switch (qemuMigrationParamTypes[i]) {
|
switch (qemuMigrationParamTypes[i]) {
|
||||||
case QEMU_MIGRATION_PARAM_TYPE_INT:
|
case QEMU_MIGRATION_PARAM_TYPE_INT:
|
||||||
rc = virJSONValueObjectAppendNumberInt(params, name, pv->value.i);
|
rc = virJSONValueObjectAppendNumberInt(params, name, pv->value.i);
|
||||||
@ -751,14 +748,10 @@ qemuMigrationParamsToJSON(qemuMigrationParamsPtr migParams)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return params;
|
return g_steal_pointer(¶ms);
|
||||||
|
|
||||||
error:
|
|
||||||
virJSONValueFree(params);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user