]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
libxl: adjust handling of libxl_device_nic objects
authorJim Fehlig <jfehlig@suse.com>
Wed, 26 May 2021 20:05:05 +0000 (14:05 -0600)
committerJim Fehlig <jfehlig@suse.com>
Tue, 1 Jun 2021 17:20:52 +0000 (11:20 -0600)
libxl objects are supposed to be initialized and disposed. Adjust
libxlMakeNic to use an already initialized object owned by the caller.

Adjust libxlMakeNicList to initialize the list of objects, before they
are filled by libxlMakeNic. The libxl_domain_config object passed to
libxlMakeNicList is owned by the caller and will be disposed with
libxl_domain_config_dispose, which also disposes embedded objects such
as libxl_device_nic.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Acked-by: Olaf Hering <olaf@aepfle.de>
src/libxl/libxl_conf.c

index 91cebf1498e516d6019ad53a44b74adaa63c60f3..fc4268db018097ccfd52f29ee4e90d67509cce74 100644 (file)
@@ -1313,8 +1313,6 @@ libxlMakeNic(virDomainDef *def,
         return -1;
     }
 
-    libxl_device_nic_init(x_nic);
-
     virMacAddrGetRaw(&l_nic->mac, x_nic->mac);
 
     /*
@@ -1502,6 +1500,7 @@ libxlMakeNicList(virDomainDef *def,  libxl_domain_config *d_config)
     size_t nnics = def->nnets;
     libxl_device_nic *x_nics;
     size_t i, nvnics = 0;
+    int ret = -1;
 
     x_nics = g_new0(libxl_device_nic, nnics);
 
@@ -1509,8 +1508,9 @@ libxlMakeNicList(virDomainDef *def,  libxl_domain_config *d_config)
         if (virDomainNetGetActualType(l_nics[i]) == VIR_DOMAIN_NET_TYPE_HOSTDEV)
             continue;
 
+        libxl_device_nic_init(&x_nics[nvnics]);
         if (libxlMakeNic(def, l_nics[i], &x_nics[nvnics], false))
-            goto error;
+            goto out;
         /*
          * The devid (at least right now) will not get initialized by
          * libxl in the setup case but is required for starting the
@@ -1521,18 +1521,14 @@ libxlMakeNicList(virDomainDef *def,  libxl_domain_config *d_config)
 
         nvnics++;
     }
+    ret = 0;
 
+ out:
     VIR_SHRINK_N(x_nics, nnics, nnics - nvnics);
     d_config->nics = x_nics;
     d_config->num_nics = nvnics;
 
-    return 0;
-
- error:
-    for (i = 0; i < nnics; i++)
-        libxl_device_nic_dispose(&x_nics[i]);
-    VIR_FREE(x_nics);
-    return -1;
+    return ret;
 }
 
 int