]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuBuildInterfaceCommandLine: Reorder VIR_FREE
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 2 Nov 2018 15:12:45 +0000 (16:12 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 5 Nov 2018 07:52:56 +0000 (08:52 +0100)
When we have variables A, B, C then there are two ways to free
them. Either in the order they are declared or the reversed one.
Any other ordering is confusing. In this commit I'm reordering
calls to VIR_FREE in the reversed order.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
src/qemu/qemu_command.c

index 6e3ff6766082a6b370cd891b4f2c297e919849d4..0d5578b4984204b902dd2076e11ed7c0883898f1 100644 (file)
@@ -8328,7 +8328,8 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
                               int **nicindexes)
 {
     int ret = -1;
-    char *nic = NULL, *host = NULL;
+    char *nic = NULL;
+    char *host = NULL;
     int *tapfd = NULL;
     size_t tapfdSize = 0;
     int *vhostfd = NULL;
@@ -8595,24 +8596,24 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
         virSetError(saved_err);
         virFreeError(saved_err);
     }
-    for (i = 0; tapfd && i < tapfdSize && tapfd[i] >= 0; i++) {
-        if (ret < 0)
-            VIR_FORCE_CLOSE(tapfd[i]);
-        if (tapfdName)
-            VIR_FREE(tapfdName[i]);
-    }
     for (i = 0; vhostfd && i < vhostfdSize && vhostfd[i] >= 0; i++) {
         if (ret < 0)
             VIR_FORCE_CLOSE(vhostfd[i]);
         if (vhostfdName)
             VIR_FREE(vhostfdName[i]);
     }
-    VIR_FREE(tapfd);
+    VIR_FREE(vhostfdName);
+    for (i = 0; tapfd && i < tapfdSize && tapfd[i] >= 0; i++) {
+        if (ret < 0)
+            VIR_FORCE_CLOSE(tapfd[i]);
+        if (tapfdName)
+            VIR_FREE(tapfdName[i]);
+    }
+    VIR_FREE(tapfdName);
     VIR_FREE(vhostfd);
-    VIR_FREE(nic);
+    VIR_FREE(tapfd);
     VIR_FREE(host);
-    VIR_FREE(tapfdName);
-    VIR_FREE(vhostfdName);
+    VIR_FREE(nic);
     return ret;
 }