Use g_auto for xmlFreeDoc 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:57:18 +02:00
parent 5dae71ee8c
commit 2c426d2e30
28 changed files with 36 additions and 74 deletions

View File

@ -213,7 +213,7 @@ virDomainCheckpointDefParseString(const char *xmlStr,
unsigned int flags)
{
virDomainCheckpointDef *ret = NULL;
xmlDocPtr xml;
g_autoptr(xmlDoc) xml = NULL;
int keepBlanksDefault = xmlKeepBlanksDefault(0);
if ((xml = virXMLParse(NULL, xmlStr, _("(domain_checkpoint)"),
@ -221,7 +221,6 @@ virDomainCheckpointDefParseString(const char *xmlStr,
xmlKeepBlanksDefault(keepBlanksDefault);
ret = virDomainCheckpointDefParseNode(xml, xmlDocGetRootElement(xml),
xmlopt, parseOpaque, flags);
xmlFreeDoc(xml);
}
xmlKeepBlanksDefault(keepBlanksDefault);

View File

@ -281,7 +281,7 @@ virCPUDefParseXMLString(const char *xml,
virCPUDef **cpu,
bool validateXML)
{
xmlDocPtr doc = NULL;
g_autoptr(xmlDoc) doc = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL;
int ret = -1;
@ -299,7 +299,6 @@ virCPUDefParseXMLString(const char *xml,
ret = 0;
cleanup:
xmlFreeDoc(doc);
return ret;
}

View File

@ -20377,7 +20377,7 @@ virDomainDefParse(const char *xmlStr,
void *parseOpaque,
unsigned int flags)
{
xmlDocPtr xml = NULL;
g_autoptr(xmlDoc) xml = NULL;
virDomainDef *def = NULL;
int keepBlanksDefault = xmlKeepBlanksDefault(0);
xmlNodePtr root;
@ -20397,7 +20397,6 @@ virDomainDefParse(const char *xmlStr,
def = virDomainDefParseNode(xml, root, xmlopt, parseOpaque, flags);
cleanup:
xmlFreeDoc(xml);
xmlKeepBlanksDefault(keepBlanksDefault);
return def;
}
@ -20480,14 +20479,13 @@ virDomainObjParseFile(const char *filename,
virDomainXMLOption *xmlopt,
unsigned int flags)
{
xmlDocPtr xml;
g_autoptr(xmlDoc) xml = NULL;
virDomainObj *obj = NULL;
int keepBlanksDefault = xmlKeepBlanksDefault(0);
if ((xml = virXMLParseFile(filename))) {
obj = virDomainObjParseNode(xml, xmlDocGetRootElement(xml),
xmlopt, flags);
xmlFreeDoc(xml);
}
xmlKeepBlanksDefault(keepBlanksDefault);

View File

@ -821,12 +821,11 @@ static virInterfaceDef *
virInterfaceDefParse(const char *xmlStr,
const char *filename)
{
xmlDocPtr xml;
g_autoptr(xmlDoc) xml = NULL;
virInterfaceDef *def = NULL;
if ((xml = virXMLParse(filename, xmlStr, _("(interface_definition)"), NULL, false))) {
def = virInterfaceDefParseNode(xml, xmlDocGetRootElement(xml));
xmlFreeDoc(xml);
}
return def;

View File

@ -2174,13 +2174,12 @@ virNodeDeviceDefParse(const char *str,
virNodeDeviceDefParserCallbacks *parserCallbacks,
void *opaque)
{
xmlDocPtr xml;
g_autoptr(xmlDoc) xml = NULL;
g_autoptr(virNodeDeviceDef) def = NULL;
if ((xml = virXMLParse(filename, str, _("(node_device_definition)"), NULL, false))) {
def = virNodeDeviceDefParseNode(xml, xmlDocGetRootElement(xml),
create, virt_type);
xmlFreeDoc(xml);
}
if (parserCallbacks) {

View File

@ -2742,11 +2742,10 @@ virNWFilterDefParse(const char *xmlStr,
const char *filename)
{
virNWFilterDef *def = NULL;
xmlDocPtr xml;
g_autoptr(xmlDoc) xml = NULL;
if ((xml = virXMLParse(filename, xmlStr, _("(nwfilter_definition)"), NULL, false))) {
def = virNWFilterDefParseNode(xml, xmlDocGetRootElement(xml));
xmlFreeDoc(xml);
}
return def;

View File

@ -193,12 +193,11 @@ static virSecretDef *
virSecretDefParse(const char *xmlStr,
const char *filename)
{
xmlDocPtr xml;
g_autoptr(xmlDoc) xml = NULL;
virSecretDef *ret = NULL;
if ((xml = virXMLParse(filename, xmlStr, _("(definition_of_secret)"), NULL, false))) {
ret = secretXMLParseNode(xml, xmlDocGetRootElement(xml));
xmlFreeDoc(xml);
}
return ret;

View File

@ -447,7 +447,7 @@ virDomainSnapshotDefParseString(const char *xmlStr,
unsigned int flags)
{
virDomainSnapshotDef *ret = NULL;
xmlDocPtr xml;
g_autoptr(xmlDoc) xml = NULL;
int keepBlanksDefault = xmlKeepBlanksDefault(0);
if ((xml = virXMLParse(NULL, xmlStr, _("(domain_snapshot)"), "domainsnapshot.rng",
@ -456,7 +456,6 @@ virDomainSnapshotDefParseString(const char *xmlStr,
ret = virDomainSnapshotDefParseNode(xml, xmlDocGetRootElement(xml),
xmlopt, parseOpaque,
current, flags);
xmlFreeDoc(xml);
}
xmlKeepBlanksDefault(keepBlanksDefault);

View File

@ -1007,11 +1007,10 @@ virStoragePoolDefParse(const char *xmlStr,
const char *filename)
{
virStoragePoolDef *ret = NULL;
xmlDocPtr xml;
g_autoptr(xmlDoc) xml = NULL;
if ((xml = virXMLParse(filename, xmlStr, _("(storage_pool_definition)"), NULL, false))) {
ret = virStoragePoolDefParseNode(xml, xmlDocGetRootElement(xml));
xmlFreeDoc(xml);
}
return ret;
@ -1476,11 +1475,10 @@ virStorageVolDefParse(virStoragePoolDef *pool,
unsigned int flags)
{
virStorageVolDef *ret = NULL;
xmlDocPtr xml;
g_autoptr(xmlDoc) xml = NULL;
if ((xml = virXMLParse(filename, xmlStr, _("(storage_volume_definition)"), NULL, false))) {
ret = virStorageVolDefParseNode(pool, xml, xmlDocGetRootElement(xml), flags);
xmlFreeDoc(xml);
}
return ret;

View File

@ -294,11 +294,10 @@ virNetworkPortDefParse(const char *xmlStr,
const char *filename)
{
virNetworkPortDef *def = NULL;
xmlDocPtr xml;
g_autoptr(xmlDoc) xml = NULL;
if ((xml = virXMLParse(filename, xmlStr, _("(networkport_definition)"), NULL, false))) {
def = virNetworkPortDefParseNode(xml, xmlDocGetRootElement(xml));
xmlFreeDoc(xml);
}
return def;

View File

@ -185,11 +185,10 @@ virNWFilterBindingDefParse(const char *xmlStr,
const char *filename)
{
virNWFilterBindingDef *def = NULL;
xmlDocPtr xml;
g_autoptr(xmlDoc) xml = NULL;
if ((xml = virXMLParse(filename, xmlStr, _("(nwfilterbinding_definition)"), NULL, false))) {
def = virNWFilterBindingDefParseNode(xml, xmlDocGetRootElement(xml));
xmlFreeDoc(xml);
}
return def;

View File

@ -262,11 +262,10 @@ virNWFilterBindingObjParse(const char *xmlStr,
const char *filename)
{
virNWFilterBindingObj *obj = NULL;
xmlDocPtr xml;
g_autoptr(xmlDoc) xml = NULL;
if ((xml = virXMLParse(filename, xmlStr, _("(nwfilterbinding_status)"), NULL, false))) {
obj = virNWFilterBindingObjParseNode(xml, xmlDocGetRootElement(xml));
xmlFreeDoc(xml);
}
return obj;

View File

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

View File

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

View File

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

View File

@ -4191,7 +4191,7 @@ virQEMUCapsLoadCache(virArch hostArch,
const char *filename,
bool skipInvalidation)
{
xmlDocPtr doc = NULL;
g_autoptr(xmlDoc) doc = NULL;
int ret = -1;
size_t i;
int n;
@ -4421,7 +4421,6 @@ virQEMUCapsLoadCache(virArch hostArch,
cleanup:
VIR_FREE(str);
VIR_FREE(nodes);
xmlFreeDoc(doc);
return ret;
}

View File

@ -1431,7 +1431,7 @@ qemuMigrationCookieXMLParseStr(qemuMigrationCookie *mig,
const char *xml,
unsigned int flags)
{
xmlDocPtr doc = NULL;
g_autoptr(xmlDoc) doc = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL;
int ret = -1;
@ -1443,7 +1443,6 @@ qemuMigrationCookieXMLParseStr(qemuMigrationCookie *mig,
ret = qemuMigrationCookieXMLParse(mig, driver, qemuCaps, doc, ctxt, flags);
cleanup:
xmlFreeDoc(doc);
return ret;
}

View File

@ -568,7 +568,7 @@ static int
caps_mockup(vahControl * ctl, const char *xmlStr)
{
int rc = -1;
xmlDocPtr xml = NULL;
g_autoptr(xmlDoc) xml = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL;
char *arch;
@ -607,7 +607,6 @@ caps_mockup(vahControl * ctl, const char *xmlStr)
rc = 0;
cleanup:
xmlFreeDoc(xml);
return rc;
}

View File

@ -2892,7 +2892,7 @@ virStorageUtilGlusterExtractPoolSources(const char *host,
virStoragePoolSourceList *list,
virStoragePoolType pooltype)
{
xmlDocPtr doc = NULL;
g_autoptr(xmlDoc) doc = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL;
virStoragePoolSource *src = NULL;
size_t i;
@ -2940,7 +2940,6 @@ virStorageUtilGlusterExtractPoolSources(const char *host,
ret = nnodes;
cleanup:
xmlFreeDoc(doc);
return ret;
}

View File

@ -825,7 +825,7 @@ static xmlNodePtr
testParseXMLDocFromFile(xmlNodePtr node, const char *file, const char *type)
{
xmlNodePtr ret = NULL;
xmlDocPtr doc = NULL;
g_autoptr(xmlDoc) doc = NULL;
g_autofree char *absFile = NULL;
g_autofree char *relFile = NULL;
@ -848,7 +848,6 @@ testParseXMLDocFromFile(xmlNodePtr node, const char *file, const char *type)
}
error:
xmlFreeDoc(doc);
return ret;
}
@ -1333,7 +1332,7 @@ testOpenParse(testDriver *privconn,
static int
testOpenFromFile(virConnectPtr conn, const char *file)
{
xmlDocPtr doc = NULL;
g_autoptr(xmlDoc) doc = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL;
testDriver *privconn;
@ -1355,13 +1354,11 @@ testOpenFromFile(virConnectPtr conn, const char *file)
if (testOpenParse(privconn, file, ctxt) < 0)
goto error;
xmlFreeDoc(doc);
virObjectUnlock(privconn);
return VIR_DRV_OPEN_SUCCESS;
error:
xmlFreeDoc(doc);
virObjectUnref(privconn);
conn->privateData = NULL;
return VIR_DRV_OPEN_ERROR;
@ -1375,7 +1372,7 @@ testOpenDefault(virConnectPtr conn)
{
int ret = VIR_DRV_OPEN_ERROR;
testDriver *privconn = NULL;
xmlDocPtr doc = NULL;
g_autoptr(xmlDoc) doc = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL;
size_t i;
@ -1424,7 +1421,6 @@ testOpenDefault(virConnectPtr conn)
ret = VIR_DRV_OPEN_SUCCESS;
cleanup:
virMutexUnlock(&defaultLock);
xmlFreeDoc(doc);
return ret;
error:

View File

@ -1619,12 +1619,11 @@ int
virXMLValidateNodeAgainstSchema(const char *schemafile, xmlNodePtr node)
{
int ret;
xmlDocPtr copy = xmlNewDoc(NULL);
g_autoptr(xmlDoc) copy = xmlNewDoc(NULL);
xmlDocSetRootElement(copy, xmlCopyNode(node, true));
ret = virXMLValidateAgainstSchema(schemafile, copy);
xmlFreeDoc(copy);
return ret;
}

View File

@ -575,7 +575,7 @@ virVBoxSnapshotConfLoadVboxFile(const char *filePath,
{
int ret = -1;
virVBoxSnapshotConfMachine *machineDescription = NULL;
xmlDocPtr xml = NULL;
g_autoptr(xmlDoc) xml = NULL;
xmlNodePtr machineNode = NULL;
xmlNodePtr cur = NULL;
g_autoptr(xmlXPathContext) xPathContext = NULL;
@ -716,7 +716,6 @@ virVBoxSnapshotConfLoadVboxFile(const char *filePath,
ret = 0;
cleanup:
xmlFreeDoc(xml);
VIR_FREE(currentStateModifiedString);
VIR_FREE(currentSnapshotAttribute);
@ -954,7 +953,7 @@ virVBoxSnapshotConfSaveVboxFile(virVBoxSnapshotConfMachine *machine,
{
int ret = -1;
size_t i = 0;
xmlDocPtr xml = NULL;
g_autoptr(xmlDoc) xml = NULL;
xmlNodePtr mediaRegistryNode = NULL;
xmlNodePtr snapshotNode = NULL;
xmlNodePtr machineNode = NULL;
@ -1172,7 +1171,6 @@ virVBoxSnapshotConfSaveVboxFile(virVBoxSnapshotConfMachine *machine,
xmlUnlinkNode(machineNode);
xmlFreeNode(machineNode);
xmlFreeDoc(xml);
g_strfreev(firstRegex);
g_strfreev(secondRegex);
@ -1219,7 +1217,7 @@ virVBoxSnapshotConfGetRWDisksPathsFromLibvirtXML(const char *filePath,
int result = -1;
size_t i = 0;
char **ret = NULL;
xmlDocPtr xml = NULL;
g_autoptr(xmlDoc) xml = NULL;
g_autoptr(xmlXPathContext) xPathContext = NULL;
xmlNodePtr *nodes = NULL;
int nodeSize = 0;
@ -1258,7 +1256,6 @@ virVBoxSnapshotConfGetRWDisksPathsFromLibvirtXML(const char *filePath,
result = 0;
cleanup:
xmlFreeDoc(xml);
if (result < 0) {
g_strfreev(ret);
nodeSize = -1;
@ -1281,7 +1278,7 @@ virVBoxSnapshotConfGetRODisksPathsFromLibvirtXML(const char *filePath,
int result = -1;
size_t i = 0;
char **ret = NULL;
xmlDocPtr xml = NULL;
g_autoptr(xmlDoc) xml = NULL;
g_autoptr(xmlXPathContext) xPathContext = NULL;
xmlNodePtr *nodes = NULL;
int nodeSize = 0;
@ -1319,7 +1316,6 @@ virVBoxSnapshotConfGetRODisksPathsFromLibvirtXML(const char *filePath,
result = 0;
cleanup:
xmlFreeDoc(xml);
if (result < 0) {
g_strfreev(ret);
nodeSize = -1;

View File

@ -2789,7 +2789,7 @@ vzBakeCookie(struct _vzDriver *driver,
static vzMigrationCookie *
vzEatCookie(const char *cookiein, int cookieinlen, unsigned int flags)
{
xmlDocPtr doc = NULL;
g_autoptr(xmlDoc) doc = NULL;
g_autoptr(xmlXPathContext) ctx = NULL;
vzMigrationCookie *mig = NULL;
@ -2838,7 +2838,6 @@ vzEatCookie(const char *cookiein, int cookieinlen, unsigned int flags)
}
cleanup:
xmlFreeDoc(doc);
return mig;
error:

View File

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

View File

@ -71,7 +71,7 @@ static virCPUDef *
cpuTestLoadXML(virArch arch, const char *name)
{
char *xml = NULL;
xmlDocPtr doc = NULL;
g_autoptr(xmlDoc) doc = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL;
virCPUDef *cpu = NULL;
@ -84,7 +84,6 @@ cpuTestLoadXML(virArch arch, const char *name)
virCPUDefParseXML(ctxt, NULL, VIR_CPU_TYPE_AUTO, &cpu, false);
cleanup:
xmlFreeDoc(doc);
VIR_FREE(xml);
return cpu;
}
@ -96,7 +95,7 @@ cpuTestLoadMultiXML(virArch arch,
unsigned int *count)
{
char *xml = NULL;
xmlDocPtr doc = NULL;
g_autoptr(xmlDoc) doc = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL;
xmlNodePtr *nodes = NULL;
virCPUDef **cpus = NULL;
@ -129,7 +128,6 @@ cpuTestLoadMultiXML(virArch arch,
cleanup:
VIR_FREE(xml);
VIR_FREE(nodes);
xmlFreeDoc(doc);
return cpus;
cleanup_cpus:

View File

@ -56,7 +56,7 @@ static const char metadata2_ns[] =
static char *
getMetadataFromXML(virDomainPtr dom)
{
xmlDocPtr doc = NULL;
g_autoptr(xmlDoc) doc = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL;
xmlNodePtr node;
@ -76,7 +76,6 @@ getMetadataFromXML(virDomainPtr dom)
cleanup:
VIR_FREE(xml);
xmlFreeDoc(doc);
return ret;
}

View File

@ -51,7 +51,7 @@ static virQEMUCaps *
testQemuGetCaps(char *caps)
{
virQEMUCaps *qemuCaps = NULL;
xmlDocPtr xml;
g_autoptr(xmlDoc) xml = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL;
ssize_t i, n;
g_autofree xmlNodePtr *nodes = NULL;
@ -79,12 +79,10 @@ testQemuGetCaps(char *caps)
}
}
xmlFreeDoc(xml);
return qemuCaps;
error:
virObjectUnref(qemuCaps);
xmlFreeDoc(xml);
return NULL;
}

View File

@ -42,7 +42,7 @@ struct testSetStruct {
#define PARSE(xml, var) \
do { \
int rc; \
xmlDocPtr doc; \
g_autoptr(xmlDoc) doc = NULL; \
g_autoptr(xmlXPathContext) ctxt = NULL; \
\
if (!xml) \
@ -57,7 +57,6 @@ struct testSetStruct {
NULL, \
ctxt->node, \
true); \
xmlFreeDoc(doc); \
if (rc < 0) \
goto cleanup; \
} while (0)