mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-12 15:52:55 +00:00
virXMLParseHelper: Refactor cleanup
Switch @xml and @pctxt to g_autofree and get rid of the "error" and "cleanup" labels. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
This commit is contained in:
parent
e87eeefb3e
commit
638007f916
@ -786,8 +786,8 @@ virXMLParseHelper(int domcode,
|
|||||||
xmlXPathContextPtr *ctxt)
|
xmlXPathContextPtr *ctxt)
|
||||||
{
|
{
|
||||||
struct virParserData private;
|
struct virParserData private;
|
||||||
xmlParserCtxtPtr pctxt;
|
g_autoptr(xmlParserCtxt) pctxt = NULL;
|
||||||
xmlDocPtr xml = NULL;
|
g_autoptr(xmlDoc) xml = NULL;
|
||||||
const char *docname;
|
const char *docname;
|
||||||
|
|
||||||
if (filename)
|
if (filename)
|
||||||
@ -823,32 +823,24 @@ virXMLParseHelper(int domcode,
|
|||||||
docname);
|
docname);
|
||||||
}
|
}
|
||||||
|
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xmlDocGetRootElement(xml) == NULL) {
|
if (xmlDocGetRootElement(xml) == NULL) {
|
||||||
virGenericReportError(domcode, VIR_ERR_INTERNAL_ERROR,
|
virGenericReportError(domcode, VIR_ERR_INTERNAL_ERROR,
|
||||||
"%s", _("missing root element"));
|
"%s", _("missing root element"));
|
||||||
goto error;
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctxt) {
|
if (ctxt) {
|
||||||
if (!(*ctxt = virXMLXPathContextNew(xml)))
|
if (!(*ctxt = virXMLXPathContextNew(xml)))
|
||||||
goto error;
|
return NULL;
|
||||||
|
|
||||||
(*ctxt)->node = xmlDocGetRootElement(xml);
|
(*ctxt)->node = xmlDocGetRootElement(xml);
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
return g_steal_pointer(&xml);
|
||||||
xmlFreeParserCtxt(pctxt);
|
|
||||||
|
|
||||||
return xml;
|
|
||||||
|
|
||||||
error:
|
|
||||||
xmlFreeDoc(xml);
|
|
||||||
xml = NULL;
|
|
||||||
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *virXMLPickShellSafeComment(const char *str1, const char *str2)
|
const char *virXMLPickShellSafeComment(const char *str1, const char *str2)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user