Clean up functions which grab and free the context to use VIR_AUTOPTR. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/conf/checkpoint_conf.c | 12 ++++-------- src/conf/domain_conf.c | 13 ++++--------- src/conf/interface_conf.c | 11 +++-------- src/conf/network_conf.c | 11 +++-------- src/conf/node_device_conf.c | 11 +++-------- src/conf/nwfilter_conf.c | 13 ++++--------- src/conf/snapshot_conf.c | 16 ++++++---------- src/conf/storage_conf.c | 24 ++++++++---------------- 8 files changed, 35 insertions(+), 76 deletions(-) diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c index 113d85cc14..5c998267aa 100644 --- a/src/conf/checkpoint_conf.c +++ b/src/conf/checkpoint_conf.c @@ -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 diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 2fe591c328..0ab69a9366 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -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); } diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c index 64729aea43..2b65a235ea 100644 --- a/src/conf/interface_conf.c +++ b/src/conf/interface_conf.c @@ -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); } diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index b65fb1f67a..9990d5e79d 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -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); } diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 8f8830aef1..84fcbd3e78 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -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); } diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index 21885eb7ae..d21eebf19d 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -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); } diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 8cf80aed83..61c807a71f 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -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 diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 0560994281..f6de3687ab 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -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); } -- 2.21.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list