Register automatic cleanup for virSysinfoBIOSDef and use it to refactor
the cleanup code paths in virSysinfoBIOSParseXML.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/conf/domain_conf.c | 19 ++++++-------------
src/util/virsysinfo.h | 1 +
2 files changed, 7 insertions(+), 13 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 7984a15c46..15db12876e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -12136,19 +12136,16 @@ virSysinfoBIOSParseXML(xmlNodePtr node,
virSysinfoBIOSDef **bios)
{
VIR_XPATH_NODE_AUTORESTORE(ctxt)
- int ret = -1;
- virSysinfoBIOSDef *def;
+ g_autoptr(virSysinfoBIOSDef) def = g_new0(virSysinfoBIOSDef, 1);
ctxt->node = node;
if (!virXMLNodeNameEqual(node, "bios")) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("XML does not contain expected 'bios'
element"));
- return ret;
+ return -1;
}
- def = g_new0(virSysinfoBIOSDef, 1);
-
def->vendor = virXPathString("string(entry[@name='vendor'])",
ctxt);
def->version = virXPathString("string(entry[@name='version'])",
ctxt);
def->date = virXPathString("string(entry[@name='date'])",
ctxt);
@@ -12173,20 +12170,16 @@ virSysinfoBIOSParseXML(xmlNodePtr node,
(year < 0 || (year >= 100 && year < 1900))) {
virReportError(VIR_ERR_XML_DETAIL, "%s",
_("Invalid BIOS 'date' format"));
- goto cleanup;
+ return -1;
}
}
if (!def->vendor && !def->version &&
- !def->date && !def->release) {
- g_clear_pointer(&def, virSysinfoBIOSDefFree);
- }
+ !def->date && !def->release)
+ return 0;
*bios = g_steal_pointer(&def);
- ret = 0;
- cleanup:
- virSysinfoBIOSDefFree(def);
- return ret;
+ return 0;
}
static int
diff --git a/src/util/virsysinfo.h b/src/util/virsysinfo.h
index 97e0e18ddf..899193dc81 100644
--- a/src/util/virsysinfo.h
+++ b/src/util/virsysinfo.h
@@ -142,6 +142,7 @@ struct _virSysinfoDef {
virSysinfoDef *virSysinfoRead(void);
void virSysinfoBIOSDefFree(virSysinfoBIOSDef *def);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virSysinfoBIOSDef, virSysinfoBIOSDefFree);
void virSysinfoSystemDefFree(virSysinfoSystemDef *def);
void virSysinfoBaseBoardDefClear(virSysinfoBaseBoardDef *def);
void virSysinfoChassisDefFree(virSysinfoChassisDef *def);
--
2.37.3