1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

tests: qemu: reduce scope of some variables

Reduce the scope of some variables and mark them as
g_autofree.

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 22:01:22 +02:00
parent 63c14318ce
commit 871544520f
3 changed files with 5 additions and 20 deletions

View File

@ -787,7 +787,6 @@ qemuMonitorTestProcessCommandWithArgs(qemuMonitorTestPtr test,
virJSONValuePtr val = NULL; virJSONValuePtr val = NULL;
virJSONValuePtr args; virJSONValuePtr args;
virJSONValuePtr argobj; virJSONValuePtr argobj;
char *argstr = NULL;
const char *cmdname; const char *cmdname;
size_t i; size_t i;
int ret = -1; int ret = -1;
@ -815,6 +814,8 @@ qemuMonitorTestProcessCommandWithArgs(qemuMonitorTestPtr test,
/* validate the args */ /* validate the args */
for (i = 0; i < data->nargs; i++) { for (i = 0; i < data->nargs; i++) {
qemuMonitorTestCommandArgsPtr arg = &data->args[i]; qemuMonitorTestCommandArgsPtr arg = &data->args[i];
g_autofree char *argstr = NULL;
if (!(argobj = virJSONValueObjectGet(args, arg->argname))) { if (!(argobj = virJSONValueObjectGet(args, arg->argname))) {
qemuMonitorTestError("Missing argument '%s' for command '%s'", qemuMonitorTestError("Missing argument '%s' for command '%s'",
arg->argname, arg->argname,
@ -835,15 +836,12 @@ qemuMonitorTestProcessCommandWithArgs(qemuMonitorTestPtr test,
arg->argval, argstr); arg->argval, argstr);
goto cleanup; goto cleanup;
} }
VIR_FREE(argstr);
} }
/* arguments checked out, return the response */ /* arguments checked out, return the response */
ret = qemuMonitorTestAddResponse(test, data->response); ret = qemuMonitorTestAddResponse(test, data->response);
cleanup: cleanup:
VIR_FREE(argstr);
virJSONValueFree(val); virJSONValueFree(val);
return ret; return ret;
} }

View File

@ -497,7 +497,6 @@ testQemuGetLatestCapsForArch(const char *arch,
DIR *dir = NULL; DIR *dir = NULL;
int rc; int rc;
char *fullsuffix = NULL; char *fullsuffix = NULL;
char *tmp = NULL;
unsigned long maxver = 0; unsigned long maxver = 0;
unsigned long ver; unsigned long ver;
g_autofree char *maxname = NULL; g_autofree char *maxname = NULL;
@ -509,7 +508,7 @@ testQemuGetLatestCapsForArch(const char *arch,
goto cleanup; goto cleanup;
while ((rc = virDirRead(dir, &ent, TEST_QEMU_CAPS_PATH)) > 0) { while ((rc = virDirRead(dir, &ent, TEST_QEMU_CAPS_PATH)) > 0) {
VIR_FREE(tmp); g_autofree char *tmp = NULL;
tmp = g_strdup(STRSKIP(ent->d_name, "caps_")); tmp = g_strdup(STRSKIP(ent->d_name, "caps_"));
@ -543,7 +542,6 @@ testQemuGetLatestCapsForArch(const char *arch,
ret = g_strdup_printf("%s/%s", TEST_QEMU_CAPS_PATH, maxname); ret = g_strdup_printf("%s/%s", TEST_QEMU_CAPS_PATH, maxname);
cleanup: cleanup:
VIR_FREE(tmp);
VIR_FREE(fullsuffix); VIR_FREE(fullsuffix);
virDirClose(&dir); virDirClose(&dir);
return ret; return ret;

View File

@ -42,23 +42,18 @@ static int
testIndexToDiskName(const void *data G_GNUC_UNUSED) testIndexToDiskName(const void *data G_GNUC_UNUSED)
{ {
size_t i; size_t i;
char *diskName = NULL;
for (i = 0; i < G_N_ELEMENTS(diskNames); ++i) { for (i = 0; i < G_N_ELEMENTS(diskNames); ++i) {
VIR_FREE(diskName); g_autofree char *diskName = NULL;
diskName = virIndexToDiskName(i, "sd"); diskName = virIndexToDiskName(i, "sd");
if (STRNEQ(diskNames[i], diskName)) { if (STRNEQ(diskNames[i], diskName)) {
virTestDifference(stderr, diskNames[i], diskName); virTestDifference(stderr, diskNames[i], diskName);
VIR_FREE(diskName);
return -1; return -1;
} }
} }
VIR_FREE(diskName);
return 0; return 0;
} }
@ -69,10 +64,9 @@ testDiskNameToIndex(const void *data G_GNUC_UNUSED)
{ {
size_t i; size_t i;
int idx; int idx;
char *diskName = NULL;
for (i = 0; i < 100000; ++i) { for (i = 0; i < 100000; ++i) {
VIR_FREE(diskName); g_autofree char *diskName = NULL;
diskName = virIndexToDiskName(i, "sd"); diskName = virIndexToDiskName(i, "sd");
idx = virDiskNameToIndex(diskName); idx = virDiskNameToIndex(diskName);
@ -80,15 +74,10 @@ testDiskNameToIndex(const void *data G_GNUC_UNUSED)
if (idx < 0 || idx != i) { if (idx < 0 || idx != i) {
VIR_TEST_DEBUG("\nExpect [%zu]", i); VIR_TEST_DEBUG("\nExpect [%zu]", i);
VIR_TEST_DEBUG("Actual [%d]", idx); VIR_TEST_DEBUG("Actual [%d]", idx);
VIR_FREE(diskName);
return -1; return -1;
} }
} }
VIR_FREE(diskName);
return 0; return 0;
} }