conf: Use automatic pointers for xmlXPathContext

Clean up functions which grab and free the context to use VIR_AUTOPTR.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Peter Krempa 2019-09-16 12:52:57 +02:00
parent 475777c9ec
commit 8aa2233099
8 changed files with 35 additions and 76 deletions

View File

@ -209,13 +209,12 @@ virDomainCheckpointDefParseNode(xmlDocPtr xml,
void *parseOpaque,
unsigned int flags)
{
xmlXPathContextPtr ctxt = NULL;
virDomainCheckpointDefPtr def = NULL;
VIR_AUTOPTR(xmlXPathContext) ctxt = NULL;
VIR_AUTOFREE(char *) schema = NULL;
if (!virXMLNodeNameEqual(root, "domaincheckpoint")) {
virReportError(VIR_ERR_XML_ERROR, "%s", _("domaincheckpoint"));
goto cleanup;
return NULL;
}
/* This is a new enough API to make schema validation unconditional */
@ -228,13 +227,10 @@ virDomainCheckpointDefParseNode(xmlDocPtr xml,
return NULL;
if (!(ctxt = virXMLXPathContextNew(xml)))
goto cleanup;
return NULL;
ctxt->node = root;
def = virDomainCheckpointDefParse(ctxt, caps, xmlopt, parseOpaque, flags);
cleanup:
xmlXPathFreeContext(ctxt);
return def;
return virDomainCheckpointDefParse(ctxt, caps, xmlopt, parseOpaque, flags);
}
virDomainCheckpointDefPtr

View File

@ -21600,26 +21600,21 @@ virDomainObjParseNode(xmlDocPtr xml,
virDomainXMLOptionPtr xmlopt,
unsigned int flags)
{
xmlXPathContextPtr ctxt = NULL;
virDomainObjPtr obj = NULL;
VIR_AUTOPTR(xmlXPathContext) ctxt = NULL;
if (!virXMLNodeNameEqual(root, "domstatus")) {
virReportError(VIR_ERR_XML_ERROR,
_("unexpected root element <%s>, "
"expecting <domstatus>"),
root->name);
goto cleanup;
return NULL;
}
if (!(ctxt = virXMLXPathContextNew(xml)))
goto cleanup;
return NULL;
ctxt->node = root;
obj = virDomainObjParseXML(xml, ctxt, caps, xmlopt, flags);
cleanup:
xmlXPathFreeContext(ctxt);
return obj;
return virDomainObjParseXML(xml, ctxt, caps, xmlopt, flags);
}

View File

@ -819,8 +819,7 @@ virInterfaceDefPtr
virInterfaceDefParseNode(xmlDocPtr xml,
xmlNodePtr root)
{
xmlXPathContextPtr ctxt = NULL;
virInterfaceDefPtr def = NULL;
VIR_AUTOPTR(xmlXPathContext) ctxt = NULL;
if (!virXMLNodeNameEqual(root, "interface")) {
virReportError(VIR_ERR_XML_ERROR,
@ -831,14 +830,10 @@ virInterfaceDefParseNode(xmlDocPtr xml,
}
if (!(ctxt = virXMLXPathContextNew(xml)))
goto cleanup;
return NULL;
ctxt->node = root;
def = virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_LAST);
cleanup:
xmlXPathFreeContext(ctxt);
return def;
return virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_LAST);
}

View File

@ -2114,8 +2114,7 @@ virNetworkDefParseNode(xmlDocPtr xml,
xmlNodePtr root,
virNetworkXMLOptionPtr xmlopt)
{
xmlXPathContextPtr ctxt = NULL;
virNetworkDefPtr def = NULL;
VIR_AUTOPTR(xmlXPathContext) ctxt = NULL;
if (!virXMLNodeNameEqual(root, "network")) {
virReportError(VIR_ERR_XML_ERROR,
@ -2126,14 +2125,10 @@ virNetworkDefParseNode(xmlDocPtr xml,
}
if (!(ctxt = virXMLXPathContextNew(xml)))
goto cleanup;
return NULL;
ctxt->node = root;
def = virNetworkDefParseXML(ctxt, xmlopt);
cleanup:
xmlXPathFreeContext(ctxt);
return def;
return virNetworkDefParseXML(ctxt, xmlopt);
}

View File

@ -2052,8 +2052,7 @@ virNodeDeviceDefParseNode(xmlDocPtr xml,
int create,
const char *virt_type)
{
xmlXPathContextPtr ctxt = NULL;
virNodeDeviceDefPtr def = NULL;
VIR_AUTOPTR(xmlXPathContext) ctxt = NULL;
if (!virXMLNodeNameEqual(root, "device")) {
virReportError(VIR_ERR_XML_ERROR,
@ -2064,14 +2063,10 @@ virNodeDeviceDefParseNode(xmlDocPtr xml,
}
if (!(ctxt = virXMLXPathContextNew(xml)))
goto cleanup;
return NULL;
ctxt->node = root;
def = virNodeDeviceDefParseXML(ctxt, create, virt_type);
cleanup:
xmlXPathFreeContext(ctxt);
return def;
return virNodeDeviceDefParseXML(ctxt, create, virt_type);
}

View File

@ -2746,25 +2746,20 @@ virNWFilterDefPtr
virNWFilterDefParseNode(xmlDocPtr xml,
xmlNodePtr root)
{
xmlXPathContextPtr ctxt = NULL;
virNWFilterDefPtr def = NULL;
VIR_AUTOPTR(xmlXPathContext) ctxt = NULL;
if (STRNEQ((const char *)root->name, "filter")) {
virReportError(VIR_ERR_XML_ERROR,
"%s",
_("unknown root element for nw filter"));
goto cleanup;
return NULL;
}
if (!(ctxt = virXMLXPathContextNew(xml)))
goto cleanup;
return NULL;
ctxt->node = root;
def = virNWFilterDefParseXML(ctxt);
cleanup:
xmlXPathFreeContext(ctxt);
return def;
return virNWFilterDefParseXML(ctxt);
}

View File

@ -430,12 +430,11 @@ virDomainSnapshotDefParseNode(xmlDocPtr xml,
bool *current,
unsigned int flags)
{
xmlXPathContextPtr ctxt = NULL;
virDomainSnapshotDefPtr def = NULL;
VIR_AUTOPTR(xmlXPathContext) ctxt = NULL;
if (!virXMLNodeNameEqual(root, "domainsnapshot")) {
virReportError(VIR_ERR_XML_ERROR, "%s", _("domainsnapshot"));
goto cleanup;
return NULL;
}
if (flags & VIR_DOMAIN_SNAPSHOT_PARSE_VALIDATE) {
@ -445,19 +444,16 @@ virDomainSnapshotDefParseNode(xmlDocPtr xml,
abs_top_srcdir "/docs/schemas",
PKGDATADIR "/schemas");
if (!schema)
goto cleanup;
return NULL;
if (virXMLValidateAgainstSchema(schema, xml) < 0)
goto cleanup;
return NULL;
}
if (!(ctxt = virXMLXPathContextNew(xml)))
goto cleanup;
return NULL;
ctxt->node = root;
def = virDomainSnapshotDefParse(ctxt, caps, xmlopt, parseOpaque, current, flags);
cleanup:
xmlXPathFreeContext(ctxt);
return def;
return virDomainSnapshotDefParse(ctxt, caps, xmlopt, parseOpaque, current, flags);
}
virDomainSnapshotDefPtr

View File

@ -1013,25 +1013,21 @@ virStoragePoolDefPtr
virStoragePoolDefParseNode(xmlDocPtr xml,
xmlNodePtr root)
{
xmlXPathContextPtr ctxt = NULL;
virStoragePoolDefPtr def = NULL;
VIR_AUTOPTR(xmlXPathContext) ctxt = NULL;
if (!virXMLNodeNameEqual(root, "pool")) {
virReportError(VIR_ERR_XML_ERROR,
_("unexpected root element <%s>, "
"expecting <pool>"),
root->name);
goto cleanup;
return NULL;
}
if (!(ctxt = virXMLXPathContextNew(xml)))
goto cleanup;
return NULL;
ctxt->node = root;
def = virStoragePoolDefParseXML(ctxt);
cleanup:
xmlXPathFreeContext(ctxt);
return def;
return virStoragePoolDefParseXML(ctxt);
}
@ -1454,25 +1450,21 @@ virStorageVolDefParseNode(virStoragePoolDefPtr pool,
xmlNodePtr root,
unsigned int flags)
{
xmlXPathContextPtr ctxt = NULL;
virStorageVolDefPtr def = NULL;
VIR_AUTOPTR(xmlXPathContext) ctxt = NULL;
if (!virXMLNodeNameEqual(root, "volume")) {
virReportError(VIR_ERR_XML_ERROR,
_("unexpected root element <%s>, "
"expecting <volume>"),
root->name);
goto cleanup;
return NULL;
}
if (!(ctxt = virXMLXPathContextNew(xml)))
goto cleanup;
return NULL;
ctxt->node = root;
def = virStorageVolDefParseXML(pool, ctxt, flags);
cleanup:
xmlXPathFreeContext(ctxt);
return def;
return virStorageVolDefParseXML(pool, ctxt, flags);
}