6ae9ed
From bb29aaf4fd23afd3e51227f415816707d28cfadb Mon Sep 17 00:00:00 2001
6ae9ed
Message-Id: <bb29aaf4fd23afd3e51227f415816707d28cfadb@dist-git>
6ae9ed
From: Michal Privoznik <mprivozn@redhat.com>
6ae9ed
Date: Fri, 5 Aug 2016 14:35:24 +0200
6ae9ed
Subject: [PATCH] qemuBuildMachineCommandLine: Follow our pattern
6ae9ed
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1304483
6ae9ed
6ae9ed
We use 'goto cleanup' for a reason. If a function can exit at
6ae9ed
many places but doesn't follow the pattern, it has to copy the
6ae9ed
free code in multiple places.
6ae9ed
6ae9ed
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6ae9ed
(cherry picked from commit 90b42f0fad5ee3395cf26c0cfc0a8bd1ad1753bb)
6ae9ed
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6ae9ed
---
6ae9ed
 src/qemu/qemu_command.c | 39 ++++++++++++++++++---------------------
6ae9ed
 1 file changed, 18 insertions(+), 21 deletions(-)
6ae9ed
6ae9ed
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
6ae9ed
index b6a7798..1a5c6dc 100644
6ae9ed
--- a/src/qemu/qemu_command.c
6ae9ed
+++ b/src/qemu/qemu_command.c
6ae9ed
@@ -6956,7 +6956,9 @@ qemuBuildMachineCommandLine(virCommandPtr cmd,
6ae9ed
                             const virDomainDef *def,
6ae9ed
                             virQEMUCapsPtr qemuCaps)
6ae9ed
 {
6ae9ed
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
6ae9ed
     bool obsoleteAccel = false;
6ae9ed
+    int ret = -1;
6ae9ed
 
6ae9ed
     /* This should *never* be NULL, since we always provide
6ae9ed
      * a machine in the capabilities data for QEMU. So this
6ae9ed
@@ -6981,7 +6983,7 @@ qemuBuildMachineCommandLine(virCommandPtr cmd,
6ae9ed
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
6ae9ed
                            _("disable shared memory is not available "
6ae9ed
                              "with this QEMU binary"));
6ae9ed
-             return -1;
6ae9ed
+            return -1;
6ae9ed
         }
6ae9ed
 
6ae9ed
         obsoleteAccel = true;
6ae9ed
@@ -6993,7 +6995,6 @@ qemuBuildMachineCommandLine(virCommandPtr cmd,
6ae9ed
             return -1;
6ae9ed
         }
6ae9ed
     } else {
6ae9ed
-        virBuffer buf = VIR_BUFFER_INITIALIZER;
6ae9ed
         virTristateSwitch vmport = def->features[VIR_DOMAIN_FEATURE_VMPORT];
6ae9ed
 
6ae9ed
         virCommandAddArg(cmd, "-machine");
6ae9ed
@@ -7017,8 +7018,7 @@ qemuBuildMachineCommandLine(virCommandPtr cmd,
6ae9ed
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
6ae9ed
                                _("vmport is not available "
6ae9ed
                                  "with this QEMU binary"));
6ae9ed
-                virBufferFreeAndReset(&buf;;
6ae9ed
-                return -1;
6ae9ed
+                goto cleanup;
6ae9ed
             }
6ae9ed
 
6ae9ed
             virBufferAsprintf(&buf, ",vmport=%s",
6ae9ed
@@ -7030,8 +7030,7 @@ qemuBuildMachineCommandLine(virCommandPtr cmd,
6ae9ed
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
6ae9ed
                                _("dump-guest-core is not available "
6ae9ed
                                  "with this QEMU binary"));
6ae9ed
-                virBufferFreeAndReset(&buf;;
6ae9ed
-                return -1;
6ae9ed
+                goto cleanup;
6ae9ed
             }
6ae9ed
 
6ae9ed
             virBufferAsprintf(&buf, ",dump-guest-core=%s",
6ae9ed
@@ -7039,22 +7038,19 @@ qemuBuildMachineCommandLine(virCommandPtr cmd,
6ae9ed
         }
6ae9ed
 
6ae9ed
         if (def->mem.nosharepages) {
6ae9ed
-            if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_MEM_MERGE)) {
6ae9ed
-                virBufferAddLit(&buf, ",mem-merge=off");
6ae9ed
-            } else {
6ae9ed
+            if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_MEM_MERGE)) {
6ae9ed
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
6ae9ed
                                _("disable shared memory is not available "
6ae9ed
                                  "with this QEMU binary"));
6ae9ed
-                virBufferFreeAndReset(&buf;;
6ae9ed
-                return -1;
6ae9ed
+                goto cleanup;
6ae9ed
             }
6ae9ed
+
6ae9ed
+            virBufferAddLit(&buf, ",mem-merge=off");
6ae9ed
         }
6ae9ed
 
6ae9ed
         if (def->keywrap &&
6ae9ed
-            !qemuAppendKeyWrapMachineParms(&buf, qemuCaps, def->keywrap)) {
6ae9ed
-            virBufferFreeAndReset(&buf;;
6ae9ed
-            return -1;
6ae9ed
-        }
6ae9ed
+            !qemuAppendKeyWrapMachineParms(&buf, qemuCaps, def->keywrap))
6ae9ed
+            goto cleanup;
6ae9ed
 
6ae9ed
         if (def->features[VIR_DOMAIN_FEATURE_GIC] == VIR_TRISTATE_SWITCH_ON) {
6ae9ed
             if (def->gic_version != VIR_GIC_VERSION_NONE) {
6ae9ed
@@ -7062,8 +7058,7 @@ qemuBuildMachineCommandLine(virCommandPtr cmd,
6ae9ed
                     virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
6ae9ed
                                    _("gic-version option is available "
6ae9ed
                                      "only for ARM virt machine"));
6ae9ed
-                    virBufferFreeAndReset(&buf;;
6ae9ed
-                    return -1;
6ae9ed
+                    goto cleanup;
6ae9ed
                 }
6ae9ed
 
6ae9ed
                 /* The default GIC version should not be specified on the
6ae9ed
@@ -7074,8 +7069,7 @@ qemuBuildMachineCommandLine(virCommandPtr cmd,
6ae9ed
                         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
6ae9ed
                                        _("gic-version option is not available "
6ae9ed
                                          "with this QEMU binary"));
6ae9ed
-                        virBufferFreeAndReset(&buf;;
6ae9ed
-                        return -1;
6ae9ed
+                        goto cleanup;
6ae9ed
                     }
6ae9ed
 
6ae9ed
                     virBufferAsprintf(&buf, ",gic-version=%s",
6ae9ed
@@ -7089,9 +7083,12 @@ qemuBuildMachineCommandLine(virCommandPtr cmd,
6ae9ed
 
6ae9ed
     if (obsoleteAccel &&
6ae9ed
         qemuBuildObsoleteAccelArg(cmd, def, qemuCaps) < 0)
6ae9ed
-        return -1;
6ae9ed
+        goto cleanup;
6ae9ed
 
6ae9ed
-    return 0;
6ae9ed
+    ret = 0;
6ae9ed
+ cleanup:
6ae9ed
+    virBufferFreeAndReset(&buf;;
6ae9ed
+    return ret;
6ae9ed
 }
6ae9ed
 
6ae9ed
 static int
6ae9ed
-- 
6ae9ed
2.9.2
6ae9ed