Register automatic cleanup for virSysinfoChassisDef and use it to
refactor the cleanup code paths in virSysinfoChassisParseXML.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/conf/domain_conf.c | 16 +++++-----------
src/util/virsysinfo.h | 1 +
2 files changed, 6 insertions(+), 11 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 90478f2528..e10b4d72f8 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -12323,19 +12323,16 @@ virSysinfoChassisParseXML(xmlNodePtr node,
virSysinfoChassisDef **chassisdef)
{
VIR_XPATH_NODE_AUTORESTORE(ctxt)
- int ret = -1;
- virSysinfoChassisDef *def;
+ g_autoptr(virSysinfoChassisDef) def = g_new0(virSysinfoChassisDef, 1);
ctxt->node = node;
if (!xmlStrEqual(node->name, BAD_CAST "chassis")) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("XML does not contain expected 'chassis'
element"));
- return ret;
+ return -1;
}
- def = g_new0(virSysinfoChassisDef, 1);
-
def->manufacturer =
virXPathString("string(entry[@name='manufacturer'])", ctxt);
def->version = virXPathString("string(entry[@name='version'])",
ctxt);
def->serial = virXPathString("string(entry[@name='serial'])",
ctxt);
@@ -12343,14 +12340,11 @@ virSysinfoChassisParseXML(xmlNodePtr node,
def->sku = virXPathString("string(entry[@name='sku'])", ctxt);
if (!def->manufacturer && !def->version &&
- !def->serial && !def->asset && !def->sku) {
- g_clear_pointer(&def, virSysinfoChassisDefFree);
- }
+ !def->serial && !def->asset && !def->sku)
+ return 0;
*chassisdef = g_steal_pointer(&def);
- ret = 0;
- virSysinfoChassisDefFree(def);
- return ret;
+ return 0;
}
diff --git a/src/util/virsysinfo.h b/src/util/virsysinfo.h
index d9f15b06e2..5fa91d9611 100644
--- a/src/util/virsysinfo.h
+++ b/src/util/virsysinfo.h
@@ -147,6 +147,7 @@ void virSysinfoSystemDefFree(virSysinfoSystemDef *def);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virSysinfoSystemDef, virSysinfoSystemDefFree);
void virSysinfoBaseBoardDefClear(virSysinfoBaseBoardDef *def);
void virSysinfoChassisDefFree(virSysinfoChassisDef *def);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virSysinfoChassisDef, virSysinfoChassisDefFree);
void virSysinfoOEMStringsDefFree(virSysinfoOEMStringsDef *def);
void virSysinfoDefFree(virSysinfoDef *def);
--
2.37.3