qemuMigrationCapsCheck: Refactor variable cleanup

Use automatic memory allocation to simplify the code and remove the need
for a 'cleanup:' label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2020-08-19 13:20:13 +02:00
parent d9115e7b0f
commit 9ea633f94f

View File

@ -1352,11 +1352,10 @@ qemuMigrationCapsCheck(virQEMUDriverPtr driver,
int asyncJob) int asyncJob)
{ {
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
virBitmapPtr migEvent = NULL; g_autoptr(virBitmap) migEvent = NULL;
virJSONValuePtr json = NULL; g_autoptr(virJSONValue) json = NULL;
char **caps = NULL; g_auto(GStrv) caps = NULL;
char **capStr; char **capStr;
int ret = -1;
int rc; int rc;
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
@ -1365,16 +1364,14 @@ qemuMigrationCapsCheck(virQEMUDriverPtr driver,
rc = qemuMonitorGetMigrationCapabilities(priv->mon, &caps); rc = qemuMonitorGetMigrationCapabilities(priv->mon, &caps);
if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0) if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
goto cleanup; return -1;
if (!caps) { if (!caps)
ret = 0; return 0;
goto cleanup;
}
priv->migrationCaps = virBitmapNew(QEMU_MIGRATION_CAP_LAST); priv->migrationCaps = virBitmapNew(QEMU_MIGRATION_CAP_LAST);
if (!priv->migrationCaps) if (!priv->migrationCaps)
goto cleanup; return -1;
for (capStr = caps; *capStr; capStr++) { for (capStr = caps; *capStr; capStr++) {
int cap = qemuMigrationCapabilityTypeFromString(*capStr); int cap = qemuMigrationCapabilityTypeFromString(*capStr);
@ -1390,21 +1387,21 @@ qemuMigrationCapsCheck(virQEMUDriverPtr driver,
if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_MIGRATION_EVENT)) { if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_MIGRATION_EVENT)) {
migEvent = virBitmapNew(QEMU_MIGRATION_CAP_LAST); migEvent = virBitmapNew(QEMU_MIGRATION_CAP_LAST);
if (!migEvent) if (!migEvent)
goto cleanup; return -1;
ignore_value(virBitmapSetBit(migEvent, QEMU_MIGRATION_CAP_EVENTS)); ignore_value(virBitmapSetBit(migEvent, QEMU_MIGRATION_CAP_EVENTS));
if (!(json = qemuMigrationCapsToJSON(migEvent, migEvent))) if (!(json = qemuMigrationCapsToJSON(migEvent, migEvent)))
goto cleanup; return -1;
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
goto cleanup; return -1;
rc = qemuMonitorSetMigrationCapabilities(priv->mon, json); rc = qemuMonitorSetMigrationCapabilities(priv->mon, json);
json = NULL; json = NULL;
if (qemuDomainObjExitMonitor(driver, vm) < 0) if (qemuDomainObjExitMonitor(driver, vm) < 0)
goto cleanup; return -1;
if (rc < 0) { if (rc < 0) {
virResetLastError(); virResetLastError();
@ -1420,13 +1417,7 @@ qemuMigrationCapsCheck(virQEMUDriverPtr driver,
ignore_value(virBitmapClearBit(priv->migrationCaps, ignore_value(virBitmapClearBit(priv->migrationCaps,
QEMU_MIGRATION_CAP_EVENTS)); QEMU_MIGRATION_CAP_EVENTS));
ret = 0; return 0;
cleanup:
virBitmapFree(migEvent);
virJSONValueFree(json);
g_strfreev(caps);
return ret;
} }