tests: qemu: use g_autoptr where possible

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
Ján Tomko 2020-07-28 21:58:18 +02:00
parent 845fee02c1
commit bcbb026993
10 changed files with 27 additions and 56 deletions

View File

@ -175,7 +175,7 @@ testQemuAgentGetFSInfoCommon(virDomainXMLOptionPtr xmlopt,
int ret = -1;
g_autofree char *domain_filename = NULL;
qemuMonitorTestPtr ret_test = NULL;
virDomainDefPtr ret_def = NULL;
g_autoptr(virDomainDef) ret_def = NULL;
if (!test || !def)
return -1;
@ -235,8 +235,6 @@ testQemuAgentGetFSInfoCommon(virDomainXMLOptionPtr xmlopt,
cleanup:
if (ret_test)
qemuMonitorTestFree(ret_test);
virDomainDefFree(ret_def);
return ret;
}
@ -400,7 +398,7 @@ qemuAgentShutdownTestMonitorHandler(qemuMonitorTestPtr test,
const char *cmdstr)
{
struct qemuAgentShutdownTestData *data;
virJSONValuePtr val = NULL;
g_autoptr(virJSONValue) val = NULL;
virJSONValuePtr args;
const char *cmdname;
const char *mode;
@ -447,7 +445,6 @@ qemuAgentShutdownTestMonitorHandler(qemuMonitorTestPtr test,
ret = 0;
cleanup:
virJSONValueFree(val);
return ret;
}

View File

@ -987,7 +987,7 @@ mymain(void)
struct testQemuBlockBitmapBlockcopyData blockbitmapblockcopydata;
struct testQemuBlockBitmapBlockcommitData blockbitmapblockcommitdata;
char *capslatest_x86_64 = NULL;
virQEMUCapsPtr caps_x86_64 = NULL;
g_autoptr(virQEMUCaps) caps_x86_64 = NULL;
g_autoptr(virHashTable) qmp_schema_x86_64 = NULL;
virJSONValuePtr qmp_schemaroot_x86_64_blockdev_add = NULL;
g_autoptr(virStorageSource) bitmapSourceChain = NULL;

View File

@ -74,7 +74,7 @@ testQemuCaps(const void *opaque)
g_autofree char *repliesFile = NULL;
g_autofree char *capsFile = NULL;
qemuMonitorTestPtr mon = NULL;
virQEMUCapsPtr capsActual = NULL;
g_autoptr(virQEMUCaps) capsActual = NULL;
g_autofree char *binary = NULL;
g_autofree char *actual = NULL;
unsigned int fakeMicrocodeVersion = 0;
@ -134,7 +134,6 @@ testQemuCaps(const void *opaque)
ret = 0;
cleanup:
qemuMonitorTestFree(mon);
virObjectUnref(capsActual);
return ret;
}
@ -145,8 +144,8 @@ testQemuCapsCopy(const void *opaque)
int ret = -1;
const testQemuData *data = opaque;
g_autofree char *capsFile = NULL;
virQEMUCapsPtr orig = NULL;
virQEMUCapsPtr copy = NULL;
g_autoptr(virQEMUCaps) orig = NULL;
g_autoptr(virQEMUCaps) copy = NULL;
g_autofree char *actual = NULL;
capsFile = g_strdup_printf("%s/%s_%s.%s.xml",
@ -169,8 +168,6 @@ testQemuCapsCopy(const void *opaque)
ret = 0;
cleanup:
virObjectUnref(orig);
virObjectUnref(copy);
return ret;
}

View File

@ -94,7 +94,7 @@ testQemuGetCaps(char *caps)
static virCapsPtr
testGetCaps(char *capsData, const testQemuData *data)
{
virQEMUCapsPtr qemuCaps = NULL;
g_autoptr(virQEMUCaps) qemuCaps = NULL;
virCapsPtr caps = NULL;
virArch arch = virArchFromString(data->archName);
g_autofree char *binary = NULL;
@ -119,11 +119,9 @@ testGetCaps(char *capsData, const testQemuData *data)
goto error;
}
virObjectUnref(qemuCaps);
return caps;
error:
virObjectUnref(qemuCaps);
virObjectUnref(caps);
return NULL;
}
@ -137,7 +135,7 @@ testQemuCapsXML(const void *opaque)
g_autofree char *xmlFile = NULL;
g_autofree char *capsData = NULL;
g_autofree char *capsXml = NULL;
virCapsPtr capsProvided = NULL;
g_autoptr(virCaps) capsProvided = NULL;
xmlFile = g_strdup_printf("%s/caps.%s.xml", data->outputDir, data->archName);
@ -160,7 +158,6 @@ testQemuCapsXML(const void *opaque)
ret = 0;
cleanup:
virObjectUnref(capsProvided);
return ret;
}

View File

@ -244,7 +244,7 @@ testQemuHotplug(const void *data)
unsigned int device_parse_flags = 0;
virDomainObjPtr vm = NULL;
virDomainDeviceDefPtr dev = NULL;
virCapsPtr caps = NULL;
g_autoptr(virCaps) caps = NULL;
qemuMonitorTestPtr test_mon = NULL;
qemuDomainObjPrivatePtr priv = NULL;
@ -349,7 +349,6 @@ testQemuHotplug(const void *data)
test->vm = NULL;
}
virDomainDeviceDefFree(dev);
virObjectUnref(caps);
qemuMonitorTestFree(test_mon);
return ((ret < 0 && fail) || (!ret && !fail)) ? 0 : -1;
}
@ -555,7 +554,7 @@ testQemuHotplugCpuIndividual(const void *opaque)
{
const struct testQemuHotplugCpuParams *params = opaque;
struct testQemuHotplugCpuData *data = NULL;
virBitmapPtr map = NULL;
g_autoptr(virBitmap) map = NULL;
int ret = -1;
int rc;
@ -584,7 +583,6 @@ testQemuHotplugCpuIndividual(const void *opaque)
ret = testQemuHotplugCpuFinalize(data);
cleanup:
virBitmapFree(map);
testQemuHotplugCpuDataFree(data);
return ret;
}

View File

@ -30,7 +30,7 @@ static int
testCompareMemLock(const void *data)
{
const struct testInfo *info = data;
virDomainDefPtr def = NULL;
g_autoptr(virDomainDef) def = NULL;
g_autofree char *xml = NULL;
int ret = -1;
@ -45,7 +45,6 @@ testCompareMemLock(const void *data)
ret = virTestCompareToULL(info->memlock, qemuDomainGetMemLockLimitBytes(def, false));
cleanup:
virDomainDefFree(def);
return ret;
}
@ -57,7 +56,7 @@ mymain(void)
{
int ret = 0;
g_autofree char *fakerootdir = NULL;
virQEMUCapsPtr qemuCaps = NULL;
g_autoptr(virQEMUCaps) qemuCaps = NULL;
fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
@ -145,8 +144,6 @@ mymain(void)
DO_TEST("pseries-locked+hostdev", VIR_DOMAIN_MEMORY_PARAM_UNLIMITED);
cleanup:
virObjectUnref(qemuCaps);
if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
virFileDeleteTree(fakerootdir);

View File

@ -60,9 +60,9 @@ qemuMigParamsTestXML2XML(const void *opaque)
const qemuMigParamsData *data = opaque;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
g_autofree char *xmlFile = NULL;
xmlDocPtr doc = NULL;
xmlXPathContextPtr ctxt = NULL;
qemuMigrationParamsPtr migParams = NULL;
g_autoptr(xmlDoc) doc = NULL;
g_autoptr(xmlXPathContext) ctxt = NULL;
g_autoptr(qemuMigrationParams) migParams = NULL;
g_autofree char *actualXML = NULL;
int ret = -1;
@ -86,9 +86,6 @@ qemuMigParamsTestXML2XML(const void *opaque)
ret = 0;
cleanup:
qemuMigrationParamsFree(migParams);
xmlXPathFreeContext(ctxt);
xmlFreeDoc(doc);
return ret;
}
@ -101,8 +98,8 @@ qemuMigParamsTestXML(const void *opaque)
g_autofree char *replyFile = NULL;
g_autofree char *xmlFile = NULL;
qemuMonitorTestPtr mon = NULL;
virJSONValuePtr params = NULL;
qemuMigrationParamsPtr migParams = NULL;
g_autoptr(virJSONValue) params = NULL;
g_autoptr(qemuMigrationParams) migParams = NULL;
g_autofree char *actualXML = NULL;
int ret = -1;
@ -132,8 +129,6 @@ qemuMigParamsTestXML(const void *opaque)
ret = 0;
cleanup:
virJSONValueFree(params);
qemuMigrationParamsFree(migParams);
qemuMonitorTestFree(mon);
return ret;
}
@ -146,9 +141,9 @@ qemuMigParamsTestJSON(const void *opaque)
g_autofree char *replyFile = NULL;
g_autofree char *jsonFile = NULL;
qemuMonitorTestPtr mon = NULL;
virJSONValuePtr paramsIn = NULL;
virJSONValuePtr paramsOut = NULL;
qemuMigrationParamsPtr migParams = NULL;
g_autoptr(virJSONValue) paramsIn = NULL;
g_autoptr(virJSONValue) paramsOut = NULL;
g_autoptr(qemuMigrationParams) migParams = NULL;
g_autofree char *actualJSON = NULL;
int ret = -1;
@ -177,9 +172,6 @@ qemuMigParamsTestJSON(const void *opaque)
ret = 0;
cleanup:
virJSONValueFree(paramsIn);
virJSONValueFree(paramsOut);
qemuMigrationParamsFree(migParams);
qemuMonitorTestFree(mon);
return ret;
}

View File

@ -720,7 +720,7 @@ qemuMonitorTestProcessGuestAgentSync(qemuMonitorTestPtr test,
qemuMonitorTestItemPtr item G_GNUC_UNUSED,
const char *cmdstr)
{
virJSONValuePtr val = NULL;
g_autoptr(virJSONValue) val = NULL;
virJSONValuePtr args;
unsigned long long id;
const char *cmdname;
@ -756,7 +756,6 @@ qemuMonitorTestProcessGuestAgentSync(qemuMonitorTestPtr test,
ret = qemuMonitorTestAddResponse(test, retmsg);
cleanup:
virJSONValueFree(val);
return ret;
}
@ -783,7 +782,7 @@ qemuMonitorTestProcessCommandWithArgs(qemuMonitorTestPtr test,
const char *cmdstr)
{
struct qemuMonitorTestHandlerData *data = item->opaque;
virJSONValuePtr val = NULL;
g_autoptr(virJSONValue) val = NULL;
virJSONValuePtr args;
virJSONValuePtr argobj;
const char *cmdname;
@ -841,7 +840,6 @@ qemuMonitorTestProcessCommandWithArgs(qemuMonitorTestPtr test,
ret = qemuMonitorTestAddResponse(test, data->response);
cleanup:
virJSONValueFree(val);
return ret;
}
@ -905,7 +903,7 @@ qemuMonitorTestProcessCommandWithArgStr(qemuMonitorTestPtr test,
const char *cmdstr)
{
struct qemuMonitorTestHandlerData *data = item->opaque;
virJSONValuePtr val = NULL;
g_autoptr(virJSONValue) val = NULL;
virJSONValuePtr args;
g_autofree char *argstr = NULL;
const char *cmdname;
@ -946,7 +944,6 @@ qemuMonitorTestProcessCommandWithArgStr(qemuMonitorTestPtr test,
ret = qemuMonitorTestAddResponse(test, data->response);
cleanup:
virJSONValueFree(val);
return ret;
}

View File

@ -565,9 +565,9 @@ testCompareXMLToArgv(const void *data)
int ret = -1;
virDomainObjPtr vm = NULL;
virDomainChrSourceDef monitor_chr;
virConnectPtr conn;
g_autoptr(virConnect) conn = NULL;
char *log = NULL;
virCommandPtr cmd = NULL;
g_autoptr(virCommand) cmd = NULL;
qemuDomainObjPrivatePtr priv = NULL;
if (info->arch != VIR_ARCH_NONE && info->arch != VIR_ARCH_X86_64)
@ -688,11 +688,9 @@ testCompareXMLToArgv(const void *data)
cleanup:
VIR_FREE(log);
virDomainChrSourceDefClear(&monitor_chr);
virCommandFree(cmd);
virObjectUnref(vm);
virSetConnectSecret(NULL);
virSetConnectStorage(NULL);
virObjectUnref(conn);
if (info->arch != VIR_ARCH_NONE && info->arch != VIR_ARCH_X86_64)
qemuTestSetHostArch(&driver, VIR_ARCH_NONE);
@ -716,7 +714,7 @@ mymain(void)
{
int ret = 0;
g_autofree char *fakerootdir = NULL;
virHashTablePtr capslatest = NULL;
g_autoptr(virHashTable) capslatest = NULL;
fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
@ -3362,7 +3360,6 @@ mymain(void)
VIR_FREE(driver.config->nbdTLSx509certdir);
qemuTestDriverFree(&driver);
virHashFree(capslatest);
virFileWrapperClearPrefixes();
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;

View File

@ -133,7 +133,7 @@ mymain(void)
int ret = 0;
g_autofree char *fakerootdir = NULL;
virQEMUDriverConfigPtr cfg = NULL;
virHashTablePtr capslatest = NULL;
g_autoptr(virHashTable) capslatest = NULL;
g_autoptr(virConnect) conn = NULL;
capslatest = testQemuGetLatestCaps();
@ -1499,7 +1499,6 @@ mymain(void)
if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
virFileDeleteTree(fakerootdir);
virHashFree(capslatest);
qemuTestDriverFree(&driver);
virFileWrapperClearPrefixes();