conf: Use VIR_AUTOPTR for xmlDoc and xmlXPath objects

Refactor functions using these two object types together with
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 13:16:36 +02:00
parent 8aa2233099
commit a8de158713
2 changed files with 12 additions and 24 deletions

View File

@ -16508,20 +16508,19 @@ virDomainDiskDefParse(const char *xmlStr,
virDomainXMLOptionPtr xmlopt, virDomainXMLOptionPtr xmlopt,
unsigned int flags) unsigned int flags)
{ {
xmlDocPtr xml; VIR_AUTOPTR(xmlDoc) xml = NULL;
xmlXPathContextPtr ctxt = NULL; VIR_AUTOPTR(xmlXPathContext) ctxt = NULL;
virDomainDiskDefPtr disk = NULL;
virSecurityLabelDefPtr *seclabels = NULL; virSecurityLabelDefPtr *seclabels = NULL;
size_t nseclabels = 0; size_t nseclabels = 0;
if (!(xml = virXMLParseStringCtxt(xmlStr, _("(disk_definition)"), &ctxt))) if (!(xml = virXMLParseStringCtxt(xmlStr, _("(disk_definition)"), &ctxt)))
goto cleanup; return NULL;
if (!virXMLNodeNameEqual(ctxt->node, "disk")) { if (!virXMLNodeNameEqual(ctxt->node, "disk")) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
_("expecting root element of 'disk', not '%s'"), _("expecting root element of 'disk', not '%s'"),
ctxt->node->name); ctxt->node->name);
goto cleanup; return NULL;
} }
if (def) { if (def) {
@ -16529,13 +16528,8 @@ virDomainDiskDefParse(const char *xmlStr,
nseclabels = def->nseclabels; nseclabels = def->nseclabels;
} }
disk = virDomainDiskDefParseXML(xmlopt, ctxt->node, ctxt, return virDomainDiskDefParseXML(xmlopt, ctxt->node, ctxt,
seclabels, nseclabels, flags); seclabels, nseclabels, flags);
cleanup:
xmlFreeDoc(xml);
xmlXPathFreeContext(ctxt);
return disk;
} }

View File

@ -695,36 +695,30 @@ virStoragePoolSourcePtr
virStoragePoolDefParseSourceString(const char *srcSpec, virStoragePoolDefParseSourceString(const char *srcSpec,
int pool_type) int pool_type)
{ {
xmlDocPtr doc = NULL; VIR_AUTOPTR(xmlDoc) doc = NULL;
xmlNodePtr node = NULL; xmlNodePtr node = NULL;
xmlXPathContextPtr xpath_ctxt = NULL; VIR_AUTOPTR(xmlXPathContext) xpath_ctxt = NULL;
virStoragePoolSourcePtr ret = NULL;
VIR_AUTOPTR(virStoragePoolSource) def = NULL; VIR_AUTOPTR(virStoragePoolSource) def = NULL;
if (!(doc = virXMLParseStringCtxt(srcSpec, if (!(doc = virXMLParseStringCtxt(srcSpec,
_("(storage_source_specification)"), _("(storage_source_specification)"),
&xpath_ctxt))) &xpath_ctxt)))
goto cleanup; return NULL;
if (VIR_ALLOC(def) < 0) if (VIR_ALLOC(def) < 0)
goto cleanup; return NULL;
if (!(node = virXPathNode("/source", xpath_ctxt))) { if (!(node = virXPathNode("/source", xpath_ctxt))) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("root element was not source")); _("root element was not source"));
goto cleanup; return NULL;
} }
if (virStoragePoolDefParseSource(xpath_ctxt, def, pool_type, if (virStoragePoolDefParseSource(xpath_ctxt, def, pool_type,
node) < 0) node) < 0)
goto cleanup; return NULL;
VIR_STEAL_PTR(ret, def); VIR_RETURN_PTR(def);
cleanup:
xmlFreeDoc(doc);
xmlXPathFreeContext(xpath_ctxt);
return ret;
} }