]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
lxc: fix variable storage order before call
authorAdam Julis <ajulis@redhat.com>
Tue, 15 Oct 2024 09:51:38 +0000 (11:51 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Wed, 16 Oct 2024 14:30:19 +0000 (16:30 +0200)
virDomainConfNWFilterInstantiate() was called without updated
net->ifname, it caused in some cases throwing error message. If
function failed, change is reverted.

Resolves: https://gitlab.com/libvirt/libvirt/-/issues/658
Signed-off-by: Adam Julis <ajulis@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
src/lxc/lxc_process.c

index dc6f4fc03cea71cdf50125ac1677d8879a6c7f37..083ab83ec6ad8874823478de2c1de753b0043385 100644 (file)
@@ -271,6 +271,7 @@ virLXCProcessSetupInterfaceTap(virDomainDef *vm,
 {
     g_autofree char *parentVeth = NULL;
     g_autofree char *containerVeth = NULL;
+    g_autofree char *backupIfname = NULL;
     const virNetDevVPortProfile *vport = virDomainNetGetActualVirtPortProfile(net);
 
     VIR_DEBUG("calling vethCreate()");
@@ -315,13 +316,16 @@ virLXCProcessSetupInterfaceTap(virDomainDef *vm,
             return NULL;
     }
 
+    /* success almost guaranteed, next function needs updated net->ifname */
+    backupIfname = g_steal_pointer(&net->ifname);
+    net->ifname = g_steal_pointer(&parentVeth);
+
     if (net->filter &&
-        virDomainConfNWFilterInstantiate(vm->name, vm->uuid, net, false) < 0)
+        virDomainConfNWFilterInstantiate(vm->name, vm->uuid, net, false) < 0) {
+        g_free(net->ifname);
+        net->ifname = g_steal_pointer(&backupIfname);
         return NULL;
-
-    /* success is guaranteed, so update the interface object */
-    g_free(net->ifname);
-    net->ifname = g_steal_pointer(&parentVeth);
+    }
 
     return g_steal_pointer(&containerVeth);
 }