[libvirt] [PATCH 09/11] qemuBuildControllersByTypeCommandLine: free devstr in the cleanup section

Ján Tomko jtomko at redhat.com
Wed Jan 16 07:56:14 UTC 2019


Signed-off-by: Ján Tomko <jtomko at redhat.com>
---
 src/qemu/qemu_command.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 7aafe235e2..5c7e53bb6a 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3117,12 +3117,12 @@ qemuBuildControllersByTypeCommandLine(virCommandPtr cmd,
                                       virQEMUCapsPtr qemuCaps,
                                       virDomainControllerType type)
 {
+    char *devstr = NULL;
     int ret = -1;
     size_t i;
 
     for (i = 0; i < def->ncontrollers; i++) {
         virDomainControllerDefPtr cont = def->controllers[i];
-        char *devstr;
 
         if (cont->type != type)
             continue;
@@ -3155,23 +3155,22 @@ qemuBuildControllersByTypeCommandLine(virCommandPtr cmd,
             continue;
         }
 
+        VIR_FREE(devstr);
         if (qemuBuildControllerDevStr(def, cont, qemuCaps, &devstr) < 0)
             goto cleanup;
 
         if (devstr) {
-            if (qemuCommandAddExtDevice(cmd, &cont->info) < 0) {
-                VIR_FREE(devstr);
+            if (qemuCommandAddExtDevice(cmd, &cont->info) < 0)
                 goto cleanup;
-            }
 
             virCommandAddArg(cmd, "-device");
             virCommandAddArg(cmd, devstr);
-            VIR_FREE(devstr);
         }
     }
 
     ret = 0;
  cleanup:
+    VIR_FREE(devstr);
     return ret;
 }
 
-- 
2.20.1




More information about the libvir-list mailing list