1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-26 03:21:44 +03:00

conf: domain: Refactor cleanup in virSysinfoSystemParseXML

Register automatic cleanup for virSysinfoSystemDef and use it to
refactor the cleanup code paths in virSysinfoSystemParseXML.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2022-10-06 11:20:27 +02:00
parent a574b8cd87
commit e40f8649bf
2 changed files with 9 additions and 16 deletions

View File

@ -12128,8 +12128,7 @@ virSysinfoSystemParseXML(xmlNodePtr node,
bool uuid_generated)
{
VIR_XPATH_NODE_AUTORESTORE(ctxt)
int ret = -1;
virSysinfoSystemDef *def;
g_autoptr(virSysinfoSystemDef) def = g_new0(virSysinfoSystemDef, 1);
g_autofree char *tmpUUID = NULL;
ctxt->node = node;
@ -12137,11 +12136,9 @@ virSysinfoSystemParseXML(xmlNodePtr node,
if (!virXMLNodeNameEqual(node, "system")) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("XML does not contain expected 'system' element"));
return ret;
return -1;
}
def = g_new0(virSysinfoSystemDef, 1);
def->manufacturer = virXPathString("string(entry[@name='manufacturer'])", ctxt);
def->product = virXPathString("string(entry[@name='product'])", ctxt);
def->version = virXPathString("string(entry[@name='version'])", ctxt);
@ -12153,15 +12150,14 @@ virSysinfoSystemParseXML(xmlNodePtr node,
if (virUUIDParse(tmpUUID, uuidbuf) < 0) {
virReportError(VIR_ERR_XML_DETAIL,
"%s", _("malformed <sysinfo> uuid element"));
goto cleanup;
return -1;
}
if (uuid_generated) {
memcpy(domUUID, uuidbuf, VIR_UUID_BUFLEN);
} else if (memcmp(domUUID, uuidbuf, VIR_UUID_BUFLEN) != 0) {
virReportError(VIR_ERR_XML_DETAIL, "%s",
_("UUID mismatch between <uuid> and "
"<sysinfo>"));
goto cleanup;
_("UUID mismatch between <uuid> and <sysinfo>"));
return -1;
}
/* Although we've validated the UUID as good, virUUIDParse() is
* lax with respect to allowing extraneous "-" and " ", but the
@ -12176,15 +12172,11 @@ virSysinfoSystemParseXML(xmlNodePtr node,
def->family = virXPathString("string(entry[@name='family'])", ctxt);
if (!def->manufacturer && !def->product && !def->version &&
!def->serial && !def->uuid && !def->sku && !def->family) {
g_clear_pointer(&def, virSysinfoSystemDefFree);
}
!def->serial && !def->uuid && !def->sku && !def->family)
return 0;
*sysdef = g_steal_pointer(&def);
ret = 0;
cleanup:
virSysinfoSystemDefFree(def);
return ret;
return 0;
}
static int

View File

@ -144,6 +144,7 @@ virSysinfoDef *virSysinfoRead(void);
void virSysinfoBIOSDefFree(virSysinfoBIOSDef *def);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virSysinfoBIOSDef, virSysinfoBIOSDefFree);
void virSysinfoSystemDefFree(virSysinfoSystemDef *def);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virSysinfoSystemDef, virSysinfoSystemDefFree);
void virSysinfoBaseBoardDefClear(virSysinfoBaseBoardDef *def);
void virSysinfoChassisDefFree(virSysinfoChassisDef *def);
void virSysinfoOEMStringsDefFree(virSysinfoOEMStringsDef *def);