mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
conf: domain: Refactor cleanup in virSysinfoBIOSParseXML
Register automatic cleanup for virSysinfoBIOSDef and use it to refactor the cleanup code paths in virSysinfoBIOSParseXML. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
45029ffa54
commit
407c4b12c7
@ -12080,19 +12080,16 @@ virSysinfoBIOSParseXML(xmlNodePtr node,
|
|||||||
virSysinfoBIOSDef **bios)
|
virSysinfoBIOSDef **bios)
|
||||||
{
|
{
|
||||||
VIR_XPATH_NODE_AUTORESTORE(ctxt)
|
VIR_XPATH_NODE_AUTORESTORE(ctxt)
|
||||||
int ret = -1;
|
g_autoptr(virSysinfoBIOSDef) def = g_new0(virSysinfoBIOSDef, 1);
|
||||||
virSysinfoBIOSDef *def;
|
|
||||||
|
|
||||||
ctxt->node = node;
|
ctxt->node = node;
|
||||||
|
|
||||||
if (!virXMLNodeNameEqual(node, "bios")) {
|
if (!virXMLNodeNameEqual(node, "bios")) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("XML does not contain expected 'bios' element"));
|
_("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->vendor = virXPathString("string(entry[@name='vendor'])", ctxt);
|
||||||
def->version = virXPathString("string(entry[@name='version'])", ctxt);
|
def->version = virXPathString("string(entry[@name='version'])", ctxt);
|
||||||
def->date = virXPathString("string(entry[@name='date'])", ctxt);
|
def->date = virXPathString("string(entry[@name='date'])", ctxt);
|
||||||
@ -12117,20 +12114,16 @@ virSysinfoBIOSParseXML(xmlNodePtr node,
|
|||||||
(year < 0 || (year >= 100 && year < 1900))) {
|
(year < 0 || (year >= 100 && year < 1900))) {
|
||||||
virReportError(VIR_ERR_XML_DETAIL, "%s",
|
virReportError(VIR_ERR_XML_DETAIL, "%s",
|
||||||
_("Invalid BIOS 'date' format"));
|
_("Invalid BIOS 'date' format"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!def->vendor && !def->version &&
|
if (!def->vendor && !def->version &&
|
||||||
!def->date && !def->release) {
|
!def->date && !def->release)
|
||||||
g_clear_pointer(&def, virSysinfoBIOSDefFree);
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
*bios = g_steal_pointer(&def);
|
*bios = g_steal_pointer(&def);
|
||||||
ret = 0;
|
return 0;
|
||||||
cleanup:
|
|
||||||
virSysinfoBIOSDefFree(def);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -142,6 +142,7 @@ struct _virSysinfoDef {
|
|||||||
virSysinfoDef *virSysinfoRead(void);
|
virSysinfoDef *virSysinfoRead(void);
|
||||||
|
|
||||||
void virSysinfoBIOSDefFree(virSysinfoBIOSDef *def);
|
void virSysinfoBIOSDefFree(virSysinfoBIOSDef *def);
|
||||||
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virSysinfoBIOSDef, virSysinfoBIOSDefFree);
|
||||||
void virSysinfoSystemDefFree(virSysinfoSystemDef *def);
|
void virSysinfoSystemDefFree(virSysinfoSystemDef *def);
|
||||||
void virSysinfoBaseBoardDefClear(virSysinfoBaseBoardDef *def);
|
void virSysinfoBaseBoardDefClear(virSysinfoBaseBoardDef *def);
|
||||||
void virSysinfoChassisDefFree(virSysinfoChassisDef *def);
|
void virSysinfoChassisDefFree(virSysinfoChassisDef *def);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user