tests: use g_auto instead of VIR_FORCE_FCLOSE

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
Ján Tomko 2021-09-04 20:15:29 +02:00
parent 0047bb18bc
commit ca24cb1e9b
3 changed files with 4 additions and 11 deletions

View File

@ -101,7 +101,7 @@ testSELinuxLoadFileList(const char *testname,
{
int ret = -1;
g_autofree char *path = NULL;
FILE *fp = NULL;
g_autoptr(FILE) fp = NULL;
g_autofree char *line = NULL;
*files = NULL;
@ -151,7 +151,6 @@ testSELinuxLoadFileList(const char *testname,
ret = 0;
cleanup:
VIR_FORCE_FCLOSE(fp);
return ret;
}

View File

@ -223,7 +223,7 @@ virTestRunLog(int *ret,
int
virTestLoadFile(const char *file, char **buf)
{
FILE *fp = fopen(file, "r");
g_autoptr(FILE) fp = fopen(file, "r");
struct stat st;
char *tmp;
int len, tmplen, buflen;
@ -235,7 +235,6 @@ virTestLoadFile(const char *file, char **buf)
if (fstat(fileno(fp), &st) < 0) {
fprintf(stderr, "%s: failed to fstat: %s\n", file, g_strerror(errno));
VIR_FORCE_FCLOSE(fp);
return -1;
}
@ -263,13 +262,11 @@ virTestLoadFile(const char *file, char **buf)
}
if (ferror(fp)) {
fprintf(stderr, "%s: read failed: %s\n", file, g_strerror(errno));
VIR_FORCE_FCLOSE(fp);
VIR_FREE(*buf);
return -1;
}
}
VIR_FORCE_FCLOSE(fp);
return 0;
}

View File

@ -33,7 +33,7 @@ linuxTestCompareFiles(const char *cpuinfofile,
int ret = -1;
g_autofree char *actualData = NULL;
virNodeInfo nodeinfo;
FILE *cpuinfo;
g_autoptr(FILE) cpuinfo = NULL;
cpuinfo = fopen(cpuinfofile, "r");
if (!cpuinfo) {
@ -51,10 +51,8 @@ linuxTestCompareFiles(const char *cpuinfofile,
if (virGetLastErrorCode())
VIR_TEST_DEBUG("\n%s", virGetLastErrorMessage());
}
VIR_FORCE_FCLOSE(cpuinfo);
goto fail;
}
VIR_FORCE_FCLOSE(cpuinfo);
actualData = g_strdup_printf("CPUs: %u/%u, MHz: %u, Nodes: %u, Sockets: %u, "
"Cores: %u, Threads: %u\n",
@ -109,7 +107,7 @@ linuxCPUStatsCompareFiles(const char *cpustatfile,
{
int ret = -1;
g_autofree char *actualData = NULL;
FILE *cpustat = NULL;
g_autoptr(FILE) cpustat = NULL;
virNodeCPUStatsPtr params = NULL;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
size_t i;
@ -148,7 +146,6 @@ linuxCPUStatsCompareFiles(const char *cpustatfile,
ret = 0;
fail:
VIR_FORCE_FCLOSE(cpustat);
VIR_FREE(params);
return ret;
}