Use our modern cleanup path pattern.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/conf/domain_conf.c | 19 +++++++------------
src/conf/domain_conf.h | 1 +
2 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ac7165bad4..204b6a85e1 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -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 def;
+ return NULL;
- error:
- virDomainSoundDefFree(def);
- return NULL;
+ return g_steal_pointer(&def);
}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 88aef29912..a04f7decc6 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -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);
--
2.40.0