Use g_auto for xmlXPathContext everywhere

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Ján Tomko 2021-08-11 13:30:26 +02:00
parent 4a8ce37bf1
commit 5dae71ee8c
20 changed files with 24 additions and 51 deletions

View File

@ -282,7 +282,7 @@ virCPUDefParseXMLString(const char *xml,
bool validateXML) bool validateXML)
{ {
xmlDocPtr doc = NULL; xmlDocPtr doc = NULL;
xmlXPathContextPtr ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
int ret = -1; int ret = -1;
if (!xml) { if (!xml) {
@ -300,7 +300,6 @@ virCPUDefParseXMLString(const char *xml,
cleanup: cleanup:
xmlFreeDoc(doc); xmlFreeDoc(doc);
xmlXPathFreeContext(ctxt);
return ret; return ret;
} }

View File

@ -268,7 +268,7 @@ virNetworkPortDef *
virNetworkPortDefParseNode(xmlDocPtr xml, virNetworkPortDefParseNode(xmlDocPtr xml,
xmlNodePtr root) xmlNodePtr root)
{ {
xmlXPathContextPtr ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
virNetworkPortDef *def = NULL; virNetworkPortDef *def = NULL;
if (STRNEQ((const char *)root->name, "networkport")) { if (STRNEQ((const char *)root->name, "networkport")) {
@ -285,7 +285,6 @@ virNetworkPortDefParseNode(xmlDocPtr xml,
def = virNetworkPortDefParseXML(ctxt); def = virNetworkPortDefParseXML(ctxt);
cleanup: cleanup:
xmlXPathFreeContext(ctxt);
return def; return def;
} }

View File

@ -159,7 +159,7 @@ virNWFilterBindingDef *
virNWFilterBindingDefParseNode(xmlDocPtr xml, virNWFilterBindingDefParseNode(xmlDocPtr xml,
xmlNodePtr root) xmlNodePtr root)
{ {
xmlXPathContextPtr ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
virNWFilterBindingDef *def = NULL; virNWFilterBindingDef *def = NULL;
if (STRNEQ((const char *)root->name, "filterbinding")) { if (STRNEQ((const char *)root->name, "filterbinding")) {
@ -176,7 +176,6 @@ virNWFilterBindingDefParseNode(xmlDocPtr xml,
def = virNWFilterBindingDefParseXML(ctxt); def = virNWFilterBindingDefParseXML(ctxt);
cleanup: cleanup:
xmlXPathFreeContext(ctxt);
return def; return def;
} }

View File

@ -236,7 +236,7 @@ static virNWFilterBindingObj *
virNWFilterBindingObjParseNode(xmlDocPtr doc, virNWFilterBindingObjParseNode(xmlDocPtr doc,
xmlNodePtr root) xmlNodePtr root)
{ {
xmlXPathContextPtr ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
virNWFilterBindingObj *obj = NULL; virNWFilterBindingObj *obj = NULL;
if (STRNEQ((const char *)root->name, "filterbindingstatus")) { if (STRNEQ((const char *)root->name, "filterbindingstatus")) {
@ -253,7 +253,6 @@ virNWFilterBindingObjParseNode(xmlDocPtr doc,
obj = virNWFilterBindingObjParseXML(doc, ctxt); obj = virNWFilterBindingObjParseXML(doc, ctxt);
cleanup: cleanup:
xmlXPathFreeContext(ctxt);
return obj; return obj;
} }

View File

@ -80,7 +80,7 @@ virSaveCookieParseString(const char *xml,
virSaveCookieCallbacks *saveCookie) virSaveCookieCallbacks *saveCookie)
{ {
xmlDocPtr doc = NULL; xmlDocPtr doc = NULL;
xmlXPathContextPtr ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
int ret = -1; int ret = -1;
*obj = NULL; *obj = NULL;
@ -96,7 +96,6 @@ virSaveCookieParseString(const char *xml,
ret = virSaveCookieParseNode(ctxt, obj, saveCookie); ret = virSaveCookieParseNode(ctxt, obj, saveCookie);
cleanup: cleanup:
xmlXPathFreeContext(ctxt);
xmlFreeDoc(doc); xmlFreeDoc(doc);
return ret; return ret;
} }

View File

@ -1644,7 +1644,7 @@ virStoragePoolObjLoadState(virStoragePoolObjList *pools,
char *stateFile = NULL; char *stateFile = NULL;
virStoragePoolObj *obj = NULL; virStoragePoolObj *obj = NULL;
xmlDocPtr xml = NULL; xmlDocPtr xml = NULL;
xmlXPathContextPtr ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
xmlNodePtr node = NULL; xmlNodePtr node = NULL;
g_autoptr(virStoragePoolDef) def = NULL; g_autoptr(virStoragePoolDef) def = NULL;
@ -1688,7 +1688,6 @@ virStoragePoolObjLoadState(virStoragePoolObjList *pools,
cleanup: cleanup:
VIR_FREE(stateFile); VIR_FREE(stateFile);
xmlFreeDoc(xml); xmlFreeDoc(xml);
xmlXPathFreeContext(ctxt);
return obj; return obj;
} }

View File

@ -1224,7 +1224,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
esxVI_Fault *fault = NULL; esxVI_Fault *fault = NULL;
g_autofree char *xpathExpression = NULL; g_autofree char *xpathExpression = NULL;
xmlXPathContextPtr xpathContext = NULL; g_autoptr(xmlXPathContext) xpathContext = NULL;
xmlNodePtr responseNode = NULL; xmlNodePtr responseNode = NULL;
if (!request || !response || *response) { if (!request || !response || *response) {
@ -1385,8 +1385,6 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
esxVI_Fault_Free(&fault); esxVI_Fault_Free(&fault);
} }
xmlXPathFreeContext(xpathContext);
return result; return result;
} }

View File

@ -149,7 +149,7 @@ libxlMigrationEatCookie(const char *cookiein,
{ {
libxlMigrationCookie *mig = NULL; libxlMigrationCookie *mig = NULL;
xmlDocPtr doc = NULL; xmlDocPtr doc = NULL;
xmlXPathContextPtr ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
g_autofree char *uuidstr = NULL; g_autofree char *uuidstr = NULL;
int ret = -1; int ret = -1;
@ -216,7 +216,6 @@ libxlMigrationEatCookie(const char *cookiein,
libxlMigrationCookieFree(mig); libxlMigrationCookieFree(mig);
cleanup: cleanup:
xmlXPathFreeContext(ctxt);
xmlFreeDoc(doc); xmlFreeDoc(doc);
return ret; return ret;
} }

View File

@ -4196,7 +4196,7 @@ virQEMUCapsLoadCache(virArch hostArch,
size_t i; size_t i;
int n; int n;
xmlNodePtr *nodes = NULL; xmlNodePtr *nodes = NULL;
xmlXPathContextPtr ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
char *str = NULL; char *str = NULL;
long long int l; long long int l;
unsigned long lu; unsigned long lu;
@ -4421,7 +4421,6 @@ virQEMUCapsLoadCache(virArch hostArch,
cleanup: cleanup:
VIR_FREE(str); VIR_FREE(str);
VIR_FREE(nodes); VIR_FREE(nodes);
xmlXPathFreeContext(ctxt);
xmlFreeDoc(doc); xmlFreeDoc(doc);
return ret; return ret;
} }

View File

@ -1432,7 +1432,7 @@ qemuMigrationCookieXMLParseStr(qemuMigrationCookie *mig,
unsigned int flags) unsigned int flags)
{ {
xmlDocPtr doc = NULL; xmlDocPtr doc = NULL;
xmlXPathContextPtr ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
int ret = -1; int ret = -1;
VIR_DEBUG("xml=%s", NULLSTR(xml)); VIR_DEBUG("xml=%s", NULLSTR(xml));
@ -1443,7 +1443,6 @@ qemuMigrationCookieXMLParseStr(qemuMigrationCookie *mig,
ret = qemuMigrationCookieXMLParse(mig, driver, qemuCaps, doc, ctxt, flags); ret = qemuMigrationCookieXMLParse(mig, driver, qemuCaps, doc, ctxt, flags);
cleanup: cleanup:
xmlXPathFreeContext(ctxt);
xmlFreeDoc(doc); xmlFreeDoc(doc);
return ret; return ret;

View File

@ -569,7 +569,7 @@ caps_mockup(vahControl * ctl, const char *xmlStr)
{ {
int rc = -1; int rc = -1;
xmlDocPtr xml = NULL; xmlDocPtr xml = NULL;
xmlXPathContextPtr ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
char *arch; char *arch;
if (!(xml = virXMLParseStringCtxt(xmlStr, _("(domain_definition)"), if (!(xml = virXMLParseStringCtxt(xmlStr, _("(domain_definition)"),
@ -608,7 +608,6 @@ caps_mockup(vahControl * ctl, const char *xmlStr)
cleanup: cleanup:
xmlFreeDoc(xml); xmlFreeDoc(xml);
xmlXPathFreeContext(ctxt);
return rc; return rc;
} }

View File

@ -2893,7 +2893,7 @@ virStorageUtilGlusterExtractPoolSources(const char *host,
virStoragePoolType pooltype) virStoragePoolType pooltype)
{ {
xmlDocPtr doc = NULL; xmlDocPtr doc = NULL;
xmlXPathContextPtr ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
virStoragePoolSource *src = NULL; virStoragePoolSource *src = NULL;
size_t i; size_t i;
int nnodes; int nnodes;
@ -2940,7 +2940,6 @@ virStorageUtilGlusterExtractPoolSources(const char *host,
ret = nnodes; ret = nnodes;
cleanup: cleanup:
xmlXPathFreeContext(ctxt);
xmlFreeDoc(doc); xmlFreeDoc(doc);
return ret; return ret;

View File

@ -1334,7 +1334,7 @@ static int
testOpenFromFile(virConnectPtr conn, const char *file) testOpenFromFile(virConnectPtr conn, const char *file)
{ {
xmlDocPtr doc = NULL; xmlDocPtr doc = NULL;
xmlXPathContextPtr ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
testDriver *privconn; testDriver *privconn;
if (!(privconn = testDriverNew())) if (!(privconn = testDriverNew()))
@ -1355,14 +1355,12 @@ testOpenFromFile(virConnectPtr conn, const char *file)
if (testOpenParse(privconn, file, ctxt) < 0) if (testOpenParse(privconn, file, ctxt) < 0)
goto error; goto error;
xmlXPathFreeContext(ctxt);
xmlFreeDoc(doc); xmlFreeDoc(doc);
virObjectUnlock(privconn); virObjectUnlock(privconn);
return VIR_DRV_OPEN_SUCCESS; return VIR_DRV_OPEN_SUCCESS;
error: error:
xmlXPathFreeContext(ctxt);
xmlFreeDoc(doc); xmlFreeDoc(doc);
virObjectUnref(privconn); virObjectUnref(privconn);
conn->privateData = NULL; conn->privateData = NULL;
@ -1378,7 +1376,7 @@ testOpenDefault(virConnectPtr conn)
int ret = VIR_DRV_OPEN_ERROR; int ret = VIR_DRV_OPEN_ERROR;
testDriver *privconn = NULL; testDriver *privconn = NULL;
xmlDocPtr doc = NULL; xmlDocPtr doc = NULL;
xmlXPathContextPtr ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
size_t i; size_t i;
virMutexLock(&defaultLock); virMutexLock(&defaultLock);
@ -1426,7 +1424,6 @@ testOpenDefault(virConnectPtr conn)
ret = VIR_DRV_OPEN_SUCCESS; ret = VIR_DRV_OPEN_SUCCESS;
cleanup: cleanup:
virMutexUnlock(&defaultLock); virMutexUnlock(&defaultLock);
xmlXPathFreeContext(ctxt);
xmlFreeDoc(doc); xmlFreeDoc(doc);
return ret; return ret;

View File

@ -578,7 +578,7 @@ virVBoxSnapshotConfLoadVboxFile(const char *filePath,
xmlDocPtr xml = NULL; xmlDocPtr xml = NULL;
xmlNodePtr machineNode = NULL; xmlNodePtr machineNode = NULL;
xmlNodePtr cur = NULL; xmlNodePtr cur = NULL;
xmlXPathContextPtr xPathContext = NULL; g_autoptr(xmlXPathContext) xPathContext = NULL;
char *currentStateModifiedString = NULL; char *currentStateModifiedString = NULL;
char **searchResultTab = NULL; char **searchResultTab = NULL;
@ -716,7 +716,6 @@ virVBoxSnapshotConfLoadVboxFile(const char *filePath,
ret = 0; ret = 0;
cleanup: cleanup:
xmlXPathFreeContext(xPathContext);
xmlFreeDoc(xml); xmlFreeDoc(xml);
VIR_FREE(currentStateModifiedString); VIR_FREE(currentStateModifiedString);
@ -1221,7 +1220,7 @@ virVBoxSnapshotConfGetRWDisksPathsFromLibvirtXML(const char *filePath,
size_t i = 0; size_t i = 0;
char **ret = NULL; char **ret = NULL;
xmlDocPtr xml = NULL; xmlDocPtr xml = NULL;
xmlXPathContextPtr xPathContext = NULL; g_autoptr(xmlXPathContext) xPathContext = NULL;
xmlNodePtr *nodes = NULL; xmlNodePtr *nodes = NULL;
int nodeSize = 0; int nodeSize = 0;
*rwDisksPath = NULL; *rwDisksPath = NULL;
@ -1260,7 +1259,6 @@ virVBoxSnapshotConfGetRWDisksPathsFromLibvirtXML(const char *filePath,
cleanup: cleanup:
xmlFreeDoc(xml); xmlFreeDoc(xml);
xmlXPathFreeContext(xPathContext);
if (result < 0) { if (result < 0) {
g_strfreev(ret); g_strfreev(ret);
nodeSize = -1; nodeSize = -1;
@ -1284,7 +1282,7 @@ virVBoxSnapshotConfGetRODisksPathsFromLibvirtXML(const char *filePath,
size_t i = 0; size_t i = 0;
char **ret = NULL; char **ret = NULL;
xmlDocPtr xml = NULL; xmlDocPtr xml = NULL;
xmlXPathContextPtr xPathContext = NULL; g_autoptr(xmlXPathContext) xPathContext = NULL;
xmlNodePtr *nodes = NULL; xmlNodePtr *nodes = NULL;
int nodeSize = 0; int nodeSize = 0;
if (filePath == NULL) { if (filePath == NULL) {
@ -1322,7 +1320,6 @@ virVBoxSnapshotConfGetRODisksPathsFromLibvirtXML(const char *filePath,
cleanup: cleanup:
xmlFreeDoc(xml); xmlFreeDoc(xml);
xmlXPathFreeContext(xPathContext);
if (result < 0) { if (result < 0) {
g_strfreev(ret); g_strfreev(ret);
nodeSize = -1; nodeSize = -1;

View File

@ -2790,7 +2790,7 @@ static vzMigrationCookie *
vzEatCookie(const char *cookiein, int cookieinlen, unsigned int flags) vzEatCookie(const char *cookiein, int cookieinlen, unsigned int flags)
{ {
xmlDocPtr doc = NULL; xmlDocPtr doc = NULL;
xmlXPathContextPtr ctx = NULL; g_autoptr(xmlXPathContext) ctx = NULL;
vzMigrationCookie *mig = NULL; vzMigrationCookie *mig = NULL;
mig = g_new0(vzMigrationCookie, 1); mig = g_new0(vzMigrationCookie, 1);
@ -2838,7 +2838,6 @@ vzEatCookie(const char *cookiein, int cookieinlen, unsigned int flags)
} }
cleanup: cleanup:
xmlXPathFreeContext(ctx);
xmlFreeDoc(doc); xmlFreeDoc(doc);
return mig; return mig;

View File

@ -4579,7 +4579,7 @@ prlsdkParseSnapshotTree(const char *treexml)
{ {
virDomainSnapshotObjList *ret = NULL; virDomainSnapshotObjList *ret = NULL;
xmlDocPtr xml = NULL; xmlDocPtr xml = NULL;
xmlXPathContextPtr ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
xmlNodePtr root; xmlNodePtr root;
xmlNodePtr *nodes = NULL; xmlNodePtr *nodes = NULL;
virDomainSnapshotDef *def = NULL; virDomainSnapshotDef *def = NULL;
@ -4696,7 +4696,6 @@ prlsdkParseSnapshotTree(const char *treexml)
virDomainSnapshotObjListFree(snapshots); virDomainSnapshotObjListFree(snapshots);
VIR_FREE(nodes); VIR_FREE(nodes);
VIR_FREE(xmlstr); VIR_FREE(xmlstr);
xmlXPathFreeContext(ctxt);
xmlFreeDoc(xml); xmlFreeDoc(xml);
VIR_FREE(def); VIR_FREE(def);

View File

@ -72,7 +72,7 @@ cpuTestLoadXML(virArch arch, const char *name)
{ {
char *xml = NULL; char *xml = NULL;
xmlDocPtr doc = NULL; xmlDocPtr doc = NULL;
xmlXPathContextPtr ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
virCPUDef *cpu = NULL; virCPUDef *cpu = NULL;
xml = g_strdup_printf("%s/cputestdata/%s-%s.xml", abs_srcdir, xml = g_strdup_printf("%s/cputestdata/%s-%s.xml", abs_srcdir,
@ -84,7 +84,6 @@ cpuTestLoadXML(virArch arch, const char *name)
virCPUDefParseXML(ctxt, NULL, VIR_CPU_TYPE_AUTO, &cpu, false); virCPUDefParseXML(ctxt, NULL, VIR_CPU_TYPE_AUTO, &cpu, false);
cleanup: cleanup:
xmlXPathFreeContext(ctxt);
xmlFreeDoc(doc); xmlFreeDoc(doc);
VIR_FREE(xml); VIR_FREE(xml);
return cpu; return cpu;
@ -98,7 +97,7 @@ cpuTestLoadMultiXML(virArch arch,
{ {
char *xml = NULL; char *xml = NULL;
xmlDocPtr doc = NULL; xmlDocPtr doc = NULL;
xmlXPathContextPtr ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
xmlNodePtr *nodes = NULL; xmlNodePtr *nodes = NULL;
virCPUDef **cpus = NULL; virCPUDef **cpus = NULL;
int n; int n;
@ -130,7 +129,6 @@ cpuTestLoadMultiXML(virArch arch,
cleanup: cleanup:
VIR_FREE(xml); VIR_FREE(xml);
VIR_FREE(nodes); VIR_FREE(nodes);
xmlXPathFreeContext(ctxt);
xmlFreeDoc(doc); xmlFreeDoc(doc);
return cpus; return cpus;

View File

@ -57,7 +57,7 @@ static char *
getMetadataFromXML(virDomainPtr dom) getMetadataFromXML(virDomainPtr dom)
{ {
xmlDocPtr doc = NULL; xmlDocPtr doc = NULL;
xmlXPathContextPtr ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
xmlNodePtr node; xmlNodePtr node;
char *xml = NULL; char *xml = NULL;
@ -77,7 +77,6 @@ getMetadataFromXML(virDomainPtr dom)
cleanup: cleanup:
VIR_FREE(xml); VIR_FREE(xml);
xmlFreeDoc(doc); xmlFreeDoc(doc);
xmlXPathFreeContext(ctxt);
return ret; return ret;
} }

View File

@ -52,7 +52,7 @@ testQemuGetCaps(char *caps)
{ {
virQEMUCaps *qemuCaps = NULL; virQEMUCaps *qemuCaps = NULL;
xmlDocPtr xml; xmlDocPtr xml;
xmlXPathContextPtr ctxt = NULL; g_autoptr(xmlXPathContext) ctxt = NULL;
ssize_t i, n; ssize_t i, n;
g_autofree xmlNodePtr *nodes = NULL; g_autofree xmlNodePtr *nodes = NULL;
@ -80,13 +80,11 @@ testQemuGetCaps(char *caps)
} }
xmlFreeDoc(xml); xmlFreeDoc(xml);
xmlXPathFreeContext(ctxt);
return qemuCaps; return qemuCaps;
error: error:
virObjectUnref(qemuCaps); virObjectUnref(qemuCaps);
xmlFreeDoc(xml); xmlFreeDoc(xml);
xmlXPathFreeContext(ctxt);
return NULL; return NULL;
} }

View File

@ -43,7 +43,7 @@ struct testSetStruct {
do { \ do { \
int rc; \ int rc; \
xmlDocPtr doc; \ xmlDocPtr doc; \
xmlXPathContextPtr ctxt = NULL; \ g_autoptr(xmlXPathContext) ctxt = NULL; \
\ \
if (!xml) \ if (!xml) \
break; \ break; \
@ -58,7 +58,6 @@ struct testSetStruct {
ctxt->node, \ ctxt->node, \
true); \ true); \
xmlFreeDoc(doc); \ xmlFreeDoc(doc); \
xmlXPathFreeContext(ctxt); \
if (rc < 0) \ if (rc < 0) \
goto cleanup; \ goto cleanup; \
} while (0) } while (0)