mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-08-22 01:50:06 +03:00
conf: Convert virDomainChrSourceDefNew to return object
Let's use object referencing to handle the ChrSourceDef. A subsequent patch then can allow the monConfig to take an extra reference before dropping the domain lock to then ensure nothing free's the memory that needs to be used. Signed-off-by: John Ferlan <jferlan@redhat.com> Reviewed-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
This commit is contained in:
@ -2260,8 +2260,10 @@ virDomainChrSourceDefCopy(virDomainChrSourceDefPtr dest,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void virDomainChrSourceDefFree(virDomainChrSourceDefPtr def)
|
static void
|
||||||
|
virDomainChrSourceDefDispose(void *obj)
|
||||||
{
|
{
|
||||||
|
virDomainChrSourceDefPtr def = obj;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if (!def)
|
if (!def)
|
||||||
@ -2275,11 +2277,16 @@ void virDomainChrSourceDefFree(virDomainChrSourceDefPtr def)
|
|||||||
virSecurityDeviceLabelDefFree(def->seclabels[i]);
|
virSecurityDeviceLabelDefFree(def->seclabels[i]);
|
||||||
VIR_FREE(def->seclabels);
|
VIR_FREE(def->seclabels);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VIR_FREE(def);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
virDomainChrSourceDefFree(virDomainChrSourceDefPtr def)
|
||||||
|
{
|
||||||
|
virObjectUnref(def);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* virDomainChrSourceDefIsEqual:
|
/* virDomainChrSourceDefIsEqual:
|
||||||
* @src: Source
|
* @src: Source
|
||||||
* @tgt: Target
|
* @tgt: Target
|
||||||
@ -12211,17 +12218,39 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static virClassPtr virDomainChrSourceDefClass;
|
||||||
|
|
||||||
|
static int
|
||||||
|
virDomainChrSourceDefOnceInit(void)
|
||||||
|
{
|
||||||
|
virDomainChrSourceDefClass = virClassNew(virClassForObject(),
|
||||||
|
"virDomainChrSourceDef",
|
||||||
|
sizeof(virDomainChrSourceDef),
|
||||||
|
virDomainChrSourceDefDispose);
|
||||||
|
if (!virDomainChrSourceDefClass)
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
VIR_ONCE_GLOBAL_INIT(virDomainChrSourceDef);
|
||||||
|
|
||||||
virDomainChrSourceDefPtr
|
virDomainChrSourceDefPtr
|
||||||
virDomainChrSourceDefNew(virDomainXMLOptionPtr xmlopt)
|
virDomainChrSourceDefNew(virDomainXMLOptionPtr xmlopt)
|
||||||
{
|
{
|
||||||
virDomainChrSourceDefPtr def = NULL;
|
virDomainChrSourceDefPtr def = NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(def) < 0)
|
if (virDomainChrSourceDefInitialize() < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (!(def = virObjectNew(virDomainChrSourceDefClass)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (xmlopt && xmlopt->privateData.chrSourceNew &&
|
if (xmlopt && xmlopt->privateData.chrSourceNew &&
|
||||||
!(def->privateData = xmlopt->privateData.chrSourceNew()))
|
!(def->privateData = xmlopt->privateData.chrSourceNew())) {
|
||||||
VIR_FREE(def);
|
virObjectUnref(def);
|
||||||
|
def = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user