The <disk> XML element parser is going to be modified so that the virStorageSource bits are pre-parsed. Add virDomainDiskDefNewSource, which uses an existing 'src' pointer. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/conf/domain_conf.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 57cad6ffde..f59d17930b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2230,25 +2230,32 @@ virDomainDefGetVcpusTopology(const virDomainDef *def, } -virDomainDiskDef * -virDomainDiskDefNew(virDomainXMLOption *xmlopt) +static virDomainDiskDef * +virDomainDiskDefNewSource(virDomainXMLOption *xmlopt, + virStorageSource **src) { + void *privateData = NULL; virDomainDiskDef *ret; - ret = g_new0(virDomainDiskDef, 1); - - ret->src = virStorageSourceNew(); - if (xmlopt && xmlopt->privateData.diskNew && - !(ret->privateData = xmlopt->privateData.diskNew())) - goto error; + !(privateData = xmlopt->privateData.diskNew())) + return NULL; + + ret = g_new0(virDomainDiskDef, 1); + ret->src = g_steal_pointer(src); + ret->privateData = privateData; return ret; +} - error: - virDomainDiskDefFree(ret); - return NULL; + +virDomainDiskDef * +virDomainDiskDefNew(virDomainXMLOption *xmlopt) +{ + g_autoptr(virStorageSource) src = virStorageSourceNew(); + + return virDomainDiskDefNewSource(xmlopt, &src); } -- 2.30.2