]> xenbits.xensource.com Git - libvirt.git/commitdiff
libxlGetDHCPInterfaces: Move some variables inside the loop
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 4 Dec 2019 09:22:13 +0000 (10:22 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 17 Dec 2019 15:58:43 +0000 (16:58 +0100)
Some variables are not used outside of the for() loop. Move their
declaration to clean up the code a bit.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
src/libxl/libxl_driver.c

index 2eea0bef636cf24263efc34e82c88b5d7c129327..b04b1c1bcf572d765edc8d826e2d70cebf879e3b 100644 (file)
@@ -6232,25 +6232,27 @@ libxlGetDHCPInterfaces(virDomainObjPtr vm,
                        virDomainInterfacePtr **ifaces)
 {
     g_autoptr(virConnect) conn = NULL;
+    virDomainInterfacePtr *ifaces_ret = NULL;
+    size_t ifaces_count = 0;
     int rv = -1;
     int n_leases = 0;
-    size_t i, j;
-    size_t ifaces_count = 0;
-    virNetworkPtr network = NULL;
-    char macaddr[VIR_MAC_STRING_BUFLEN];
-    virDomainInterfacePtr iface = NULL;
     virNetworkDHCPLeasePtr *leases = NULL;
-    virDomainInterfacePtr *ifaces_ret = NULL;
+    size_t i;
 
     if (!(conn = virGetConnectNetwork()))
         return -1;
 
     for (i = 0; i < vm->def->nnets; i++) {
+        g_autoptr(virNetwork) network = NULL;
+        char macaddr[VIR_MAC_STRING_BUFLEN];
+        virDomainInterfacePtr iface = NULL;
+        size_t j;
+
         if (vm->def->nets[i]->type != VIR_DOMAIN_NET_TYPE_NETWORK)
             continue;
 
         virMacAddrFormat(&(vm->def->nets[i]->mac), macaddr);
-        virObjectUnref(network);
+
         network = virNetworkLookupByName(conn,
                                          vm->def->nets[i]->data.network.name);
         if (!network)
@@ -6300,7 +6302,6 @@ libxlGetDHCPInterfaces(virDomainObjPtr vm,
     rv = ifaces_count;
 
  cleanup:
-    virObjectUnref(network);
     if (leases) {
         for (i = 0; i < n_leases; i++)
             virNetworkDHCPLeaseFree(leases[i]);