Add automatic cleanup for variables of xmlDoc and xmlXPathContext type
to remove the cleanup section.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/conf/network_conf.c | 36 ++++++++++++++++--------------------
1 file changed, 16 insertions(+), 20 deletions(-)
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 585c87a9f4..b65fb1f67a 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -3640,57 +3640,56 @@ virNetworkDefUpdateSection(virNetworkDefPtr def,
const char *xml,
unsigned int flags) /* virNetworkUpdateFlags */
{
- int ret = -1;
- xmlDocPtr doc;
- xmlXPathContextPtr ctxt = NULL;
+ VIR_AUTOPTR(xmlDoc) doc = NULL;
+ VIR_AUTOPTR(xmlXPathContext) ctxt = NULL;
if (!(doc = virXMLParseStringCtxt(xml, _("network_update_xml"),
&ctxt)))
- goto cleanup;
+ return -1;
switch (section) {
case VIR_NETWORK_SECTION_BRIDGE:
- ret = virNetworkDefUpdateBridge(def, command, parentIndex, ctxt, flags);
+ return virNetworkDefUpdateBridge(def, command, parentIndex, ctxt, flags);
break;
case VIR_NETWORK_SECTION_DOMAIN:
- ret = virNetworkDefUpdateDomain(def, command, parentIndex, ctxt, flags);
+ return virNetworkDefUpdateDomain(def, command, parentIndex, ctxt, flags);
break;
case VIR_NETWORK_SECTION_IP:
- ret = virNetworkDefUpdateIP(def, command, parentIndex, ctxt, flags);
+ return virNetworkDefUpdateIP(def, command, parentIndex, ctxt, flags);
break;
case VIR_NETWORK_SECTION_IP_DHCP_HOST:
- ret = virNetworkDefUpdateIPDHCPHost(def, command,
+ return virNetworkDefUpdateIPDHCPHost(def, command,
parentIndex, ctxt, flags);
break;
case VIR_NETWORK_SECTION_IP_DHCP_RANGE:
- ret = virNetworkDefUpdateIPDHCPRange(def, command,
+ return virNetworkDefUpdateIPDHCPRange(def, command,
parentIndex, ctxt, flags);
break;
case VIR_NETWORK_SECTION_FORWARD:
- ret = virNetworkDefUpdateForward(def, command,
+ return virNetworkDefUpdateForward(def, command,
parentIndex, ctxt, flags);
break;
case VIR_NETWORK_SECTION_FORWARD_INTERFACE:
- ret = virNetworkDefUpdateForwardInterface(def, command,
+ return virNetworkDefUpdateForwardInterface(def, command,
parentIndex, ctxt, flags);
break;
case VIR_NETWORK_SECTION_FORWARD_PF:
- ret = virNetworkDefUpdateForwardPF(def, command,
+ return virNetworkDefUpdateForwardPF(def, command,
parentIndex, ctxt, flags);
break;
case VIR_NETWORK_SECTION_PORTGROUP:
- ret = virNetworkDefUpdatePortGroup(def, command,
+ return virNetworkDefUpdatePortGroup(def, command,
parentIndex, ctxt, flags);
break;
case VIR_NETWORK_SECTION_DNS_HOST:
- ret = virNetworkDefUpdateDNSHost(def, command,
+ return virNetworkDefUpdateDNSHost(def, command,
parentIndex, ctxt, flags);
break;
case VIR_NETWORK_SECTION_DNS_TXT:
- ret = virNetworkDefUpdateDNSTxt(def, command, parentIndex, ctxt, flags);
+ return virNetworkDefUpdateDNSTxt(def, command, parentIndex, ctxt, flags);
break;
case VIR_NETWORK_SECTION_DNS_SRV:
- ret = virNetworkDefUpdateDNSSrv(def, command, parentIndex, ctxt, flags);
+ return virNetworkDefUpdateDNSSrv(def, command, parentIndex, ctxt, flags);
break;
default:
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
@@ -3698,8 +3697,5 @@ virNetworkDefUpdateSection(virNetworkDefPtr def,
break;
}
- cleanup:
- xmlFreeDoc(doc);
- xmlXPathFreeContext(ctxt);
- return ret;
+ return -1;
}
--
2.21.0