1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-20 07:59:00 +00:00

conf: secret: Refactor cleanup in secretXMLParseNode

Use VIR_AUTO* for temporary locals and get rid of the 'cleanup' label.

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 13:44:39 +02:00
parent 8d301bd435
commit 47b35f4d0e
2 changed files with 20 additions and 26 deletions

View File

@ -3654,31 +3654,31 @@ virNetworkDefUpdateSection(virNetworkDefPtr def,
break; break;
case VIR_NETWORK_SECTION_IP_DHCP_HOST: case VIR_NETWORK_SECTION_IP_DHCP_HOST:
return virNetworkDefUpdateIPDHCPHost(def, command, return virNetworkDefUpdateIPDHCPHost(def, command,
parentIndex, ctxt, flags); parentIndex, ctxt, flags);
break; break;
case VIR_NETWORK_SECTION_IP_DHCP_RANGE: case VIR_NETWORK_SECTION_IP_DHCP_RANGE:
return virNetworkDefUpdateIPDHCPRange(def, command, return virNetworkDefUpdateIPDHCPRange(def, command,
parentIndex, ctxt, flags); parentIndex, ctxt, flags);
break; break;
case VIR_NETWORK_SECTION_FORWARD: case VIR_NETWORK_SECTION_FORWARD:
return virNetworkDefUpdateForward(def, command, return virNetworkDefUpdateForward(def, command,
parentIndex, ctxt, flags); parentIndex, ctxt, flags);
break; break;
case VIR_NETWORK_SECTION_FORWARD_INTERFACE: case VIR_NETWORK_SECTION_FORWARD_INTERFACE:
return virNetworkDefUpdateForwardInterface(def, command, return virNetworkDefUpdateForwardInterface(def, command,
parentIndex, ctxt, flags); parentIndex, ctxt, flags);
break; break;
case VIR_NETWORK_SECTION_FORWARD_PF: case VIR_NETWORK_SECTION_FORWARD_PF:
return virNetworkDefUpdateForwardPF(def, command, return virNetworkDefUpdateForwardPF(def, command,
parentIndex, ctxt, flags); parentIndex, ctxt, flags);
break; break;
case VIR_NETWORK_SECTION_PORTGROUP: case VIR_NETWORK_SECTION_PORTGROUP:
return virNetworkDefUpdatePortGroup(def, command, return virNetworkDefUpdatePortGroup(def, command,
parentIndex, ctxt, flags); parentIndex, ctxt, flags);
break; break;
case VIR_NETWORK_SECTION_DNS_HOST: case VIR_NETWORK_SECTION_DNS_HOST:
return virNetworkDefUpdateDNSHost(def, command, return virNetworkDefUpdateDNSHost(def, command,
parentIndex, ctxt, flags); parentIndex, ctxt, flags);
break; break;
case VIR_NETWORK_SECTION_DNS_TXT: case VIR_NETWORK_SECTION_DNS_TXT:
return virNetworkDefUpdateDNSTxt(def, command, parentIndex, ctxt, flags); return virNetworkDefUpdateDNSTxt(def, command, parentIndex, ctxt, flags);

View File

@ -131,33 +131,33 @@ virSecretDefParseUsage(xmlXPathContextPtr ctxt,
static virSecretDefPtr static virSecretDefPtr
secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root) secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
{ {
xmlXPathContextPtr ctxt = NULL; VIR_AUTOPTR(xmlXPathContext) ctxt = NULL;
virSecretDefPtr def = NULL, ret = NULL; VIR_AUTOPTR(virSecretDef) def = NULL;
char *prop = NULL; VIR_AUTOFREE(char *) prop = NULL;
char *uuidstr = NULL; VIR_AUTOFREE(char *) uuidstr = NULL;
if (!virXMLNodeNameEqual(root, "secret")) { if (!virXMLNodeNameEqual(root, "secret")) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
_("unexpected root element <%s>, " _("unexpected root element <%s>, "
"expecting <secret>"), "expecting <secret>"),
root->name); root->name);
goto cleanup; return NULL;
} }
if (!(ctxt = virXMLXPathContextNew(xml))) if (!(ctxt = virXMLXPathContextNew(xml)))
goto cleanup; return NULL;
ctxt->node = root; ctxt->node = root;
if (VIR_ALLOC(def) < 0) if (VIR_ALLOC(def) < 0)
goto cleanup; return NULL;
prop = virXPathString("string(./@ephemeral)", ctxt); prop = virXPathString("string(./@ephemeral)", ctxt);
if (prop != NULL) { if (prop != NULL) {
if (virStringParseYesNo(prop, &def->isephemeral) < 0) { if (virStringParseYesNo(prop, &def->isephemeral) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("invalid value of 'ephemeral'")); _("invalid value of 'ephemeral'"));
goto cleanup; return NULL;
} }
VIR_FREE(prop); VIR_FREE(prop);
} }
@ -167,7 +167,7 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
if (virStringParseYesNo(prop, &def->isprivate) < 0) { if (virStringParseYesNo(prop, &def->isprivate) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("invalid value of 'private'")); _("invalid value of 'private'"));
goto cleanup; return NULL;
} }
VIR_FREE(prop); VIR_FREE(prop);
} }
@ -177,13 +177,13 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
if (virUUIDGenerate(def->uuid) < 0) { if (virUUIDGenerate(def->uuid) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Failed to generate UUID")); "%s", _("Failed to generate UUID"));
goto cleanup; return NULL;
} }
} else { } else {
if (virUUIDParse(uuidstr, def->uuid) < 0) { if (virUUIDParse(uuidstr, def->uuid) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("malformed uuid element")); "%s", _("malformed uuid element"));
goto cleanup; return NULL;
} }
VIR_FREE(uuidstr); VIR_FREE(uuidstr);
} }
@ -191,15 +191,9 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
def->description = virXPathString("string(./description)", ctxt); def->description = virXPathString("string(./description)", ctxt);
if (virXPathNode("./usage", ctxt) != NULL if (virXPathNode("./usage", ctxt) != NULL
&& virSecretDefParseUsage(ctxt, def) < 0) && virSecretDefParseUsage(ctxt, def) < 0)
goto cleanup; return NULL;
VIR_STEAL_PTR(ret, def);
cleanup: VIR_RETURN_PTR(def);
VIR_FREE(prop);
VIR_FREE(uuidstr);
virSecretDefFree(def);
xmlXPathFreeContext(ctxt);
return ret;
} }
static virSecretDefPtr static virSecretDefPtr