conf: Register autoptr cleanup for 'virDomainSoundDef' and refactor virDomainSoundDefParseXML

Use our modern cleanup path pattern.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2023-05-09 13:35:10 +02:00
parent d6d4cfa5fc
commit 783c6bc2f0
2 changed files with 8 additions and 12 deletions

View File

@ -11654,16 +11654,15 @@ virDomainSoundDefParseXML(virDomainXMLOption *xmlopt,
xmlXPathContextPtr ctxt,
unsigned int flags)
{
virDomainSoundDef *def;
g_autoptr(virDomainSoundDef) def = g_new0(virDomainSoundDef, 1);
VIR_XPATH_NODE_AUTORESTORE(ctxt)
xmlNodePtr audioNode;
def = g_new0(virDomainSoundDef, 1);
ctxt->node = node;
if (virXMLPropEnum(node, "model", virDomainSoundModelTypeFromString,
VIR_XML_PROP_REQUIRED, &def->model) < 0)
goto error;
return NULL;
if (virDomainSoundModelSupportsCodecs(def)) {
int ncodecs;
@ -11672,7 +11671,7 @@ virDomainSoundDefParseXML(virDomainXMLOption *xmlopt,
/* parse the <codec> subelements for sound models that support it */
ncodecs = virXPathNodeSet("./codec", ctxt, &codecNodes);
if (ncodecs < 0)
goto error;
return NULL;
if (ncodecs > 0) {
size_t i;
@ -11682,7 +11681,7 @@ virDomainSoundDefParseXML(virDomainXMLOption *xmlopt,
for (i = 0; i < ncodecs; i++) {
virDomainSoundCodecDef *codec = virDomainSoundCodecDefParseXML(codecNodes[i]);
if (codec == NULL)
goto error;
return NULL;
codec->cad = def->ncodecs; /* that will do for now */
def->codecs[def->ncodecs++] = codec;
@ -11695,17 +11694,13 @@ virDomainSoundDefParseXML(virDomainXMLOption *xmlopt,
if (virXMLPropUInt(audioNode, "id", 10,
VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO,
&def->audioId) < 0)
goto error;
return NULL;
}
if (virDomainDeviceInfoParseXML(xmlopt, node, ctxt, &def->info, flags) < 0)
goto error;
return NULL;
return def;
error:
virDomainSoundDefFree(def);
return NULL;
return g_steal_pointer(&def);
}

View File

@ -3569,6 +3569,7 @@ void virDomainSoundCodecDefFree(virDomainSoundCodecDef *def);
ssize_t virDomainSoundDefFind(const virDomainDef *def,
const virDomainSoundDef *sound);
void virDomainSoundDefFree(virDomainSoundDef *def);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainSoundDef, virDomainSoundDefFree);
virDomainSoundDef *virDomainSoundDefRemove(virDomainDef *def, size_t idx);
void virDomainAudioDefFree(virDomainAudioDef *def);
void virDomainMemballoonDefFree(virDomainMemballoonDef *def);