libxl objects are supposed to be initialized and disposed.
Adjust libxlMakeNic to use an already initialized object, it is owned by
the caller.
Adjust libxlMakeNicList to initialize the list of objects, before they
are filled by libxlMakeNic. In case of error the objects are disposed
by libxl_domain_config_dispose.
Signed-off-by: Olaf Hering <olaf(a)aepfle.de>
---
src/libxl/libxl_conf.c | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 2ecbcf6911..c672bafbe9 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1335,8 +1335,6 @@ libxlMakeNic(virDomainDef *def,
return -1;
}
- libxl_device_nic_init(x_nic);
-
virMacAddrGetRaw(&l_nic->mac, x_nic->mac);
/*
@@ -1531,8 +1529,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;
+ return -1;
/*
* The devid (at least right now) will not get initialized by
* libxl in the setup case but is required for starting the
@@ -1549,12 +1548,6 @@ libxlMakeNicList(virDomainDef *def, libxl_domain_config
*d_config)
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;
}
int