We use 'goto cleanup' for a reason. If a function can exit at
many places but doesn't follow the pattern, it has to copy the
free code in multiple places.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/qemu/qemu_command.c | 39 ++++++++++++++++++---------------------
1 file changed, 18 insertions(+), 21 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 3dc131b..6295eeb 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -6751,7 +6751,9 @@ qemuBuildMachineCommandLine(virCommandPtr cmd,
const virDomainDef *def,
virQEMUCapsPtr qemuCaps)
{
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
bool obsoleteAccel = false;
+ int ret = -1;
/* This should *never* be NULL, since we always provide
* a machine in the capabilities data for QEMU. So this
@@ -6776,7 +6778,7 @@ qemuBuildMachineCommandLine(virCommandPtr cmd,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("disable shared memory is not available "
"with this QEMU binary"));
- return -1;
+ return -1;
}
obsoleteAccel = true;
@@ -6788,7 +6790,6 @@ qemuBuildMachineCommandLine(virCommandPtr cmd,
return -1;
}
} else {
- virBuffer buf = VIR_BUFFER_INITIALIZER;
virTristateSwitch vmport = def->features[VIR_DOMAIN_FEATURE_VMPORT];
virCommandAddArg(cmd, "-machine");
@@ -6812,8 +6813,7 @@ qemuBuildMachineCommandLine(virCommandPtr cmd,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("vmport is not available "
"with this QEMU binary"));
- virBufferFreeAndReset(&buf);
- return -1;
+ goto cleanup;
}
virBufferAsprintf(&buf, ",vmport=%s",
@@ -6825,8 +6825,7 @@ qemuBuildMachineCommandLine(virCommandPtr cmd,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("dump-guest-core is not available "
"with this QEMU binary"));
- virBufferFreeAndReset(&buf);
- return -1;
+ goto cleanup;
}
virBufferAsprintf(&buf, ",dump-guest-core=%s",
@@ -6834,22 +6833,19 @@ qemuBuildMachineCommandLine(virCommandPtr cmd,
}
if (def->mem.nosharepages) {
- if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_MEM_MERGE)) {
- virBufferAddLit(&buf, ",mem-merge=off");
- } else {
+ if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_MEM_MERGE)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("disable shared memory is not available "
"with this QEMU binary"));
- virBufferFreeAndReset(&buf);
- return -1;
+ goto cleanup;
}
+
+ virBufferAddLit(&buf, ",mem-merge=off");
}
if (def->keywrap &&
- !qemuAppendKeyWrapMachineParms(&buf, qemuCaps, def->keywrap)) {
- virBufferFreeAndReset(&buf);
- return -1;
- }
+ !qemuAppendKeyWrapMachineParms(&buf, qemuCaps, def->keywrap))
+ goto cleanup;
if (def->features[VIR_DOMAIN_FEATURE_GIC] == VIR_TRISTATE_SWITCH_ON) {
if (def->gic_version != VIR_GIC_VERSION_NONE) {
@@ -6857,8 +6853,7 @@ qemuBuildMachineCommandLine(virCommandPtr cmd,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("gic-version option is available "
"only for ARM virt machine"));
- virBufferFreeAndReset(&buf);
- return -1;
+ goto cleanup;
}
/* The default GIC version should not be specified on the
@@ -6869,8 +6864,7 @@ qemuBuildMachineCommandLine(virCommandPtr cmd,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("gic-version option is not available
"
"with this QEMU binary"));
- virBufferFreeAndReset(&buf);
- return -1;
+ goto cleanup;
}
virBufferAsprintf(&buf, ",gic-version=%s",
@@ -6884,9 +6878,12 @@ qemuBuildMachineCommandLine(virCommandPtr cmd,
if (obsoleteAccel &&
qemuBuildObsoleteAccelArg(cmd, def, qemuCaps) < 0)
- return -1;
+ goto cleanup;
- return 0;
+ ret = 0;
+ cleanup:
+ virBufferFreeAndReset(&buf);
+ return ret;
}
static int
--
2.8.4