]> xenbits.xensource.com Git - libvirt.git/commitdiff
vmx: allocate space for network interfaces if needed
authorPino Toscano <ptoscano@redhat.com>
Wed, 28 Mar 2018 11:40:19 +0000 (13:40 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Sun, 1 Apr 2018 10:43:42 +0000 (12:43 +0200)
Dynamically grow the array of network interfaces for each interface
read, instead of using a single array of size 4.  This way, in the
future it will be easier to not limit the number of network interfaces
(which this patch still does not change).

Signed-off-by: Pino Toscano <ptoscano@redhat.com>
src/vmx/vmx.c

index ba47a87b71efe9fc1509a35282f71298294e59db..fd9b559503ce8a9e2dd93d5237919f4615f20208 100644 (file)
@@ -1751,19 +1751,16 @@ virVMXParseConfig(virVMXContext *ctx,
     }
 
     /* def:nets */
-    if (VIR_ALLOC_N(def->nets, 4) < 0)
-        goto cleanup;
-
-    def->nnets = 0;
-
     for (controller = 0; controller < 4; ++controller) {
-        if (virVMXParseEthernet(conf, controller,
-                                &def->nets[def->nnets]) < 0) {
+        virDomainNetDefPtr net = NULL;
+        if (virVMXParseEthernet(conf, controller, &net) < 0)
             goto cleanup;
-        }
 
-        if (def->nets[def->nnets] != NULL)
-            ++def->nnets;
+        if (!net)
+            continue;
+
+        if (VIR_APPEND_ELEMENT(def->nets, def->nnets, net) < 0)
+            goto cleanup;
     }
 
     /* def:inputs */