[libvirt PATCH 14/24] tests: use g_auto instead of VIR_FORCE_FCLOSE

Ján Tomko jtomko at redhat.com
Sat Sep 4 20:44:12 UTC 2021


Signed-off-by: Ján Tomko <jtomko at redhat.com>
---
 tests/securityselinuxlabeltest.c | 3 +--
 tests/testutils.c                | 5 +----
 tests/virhostcputest.c           | 7 ++-----
 3 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabeltest.c
index cd604eda31..2fb6e0c6b7 100644
--- a/tests/securityselinuxlabeltest.c
+++ b/tests/securityselinuxlabeltest.c
@@ -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;
 }
 
diff --git a/tests/testutils.c b/tests/testutils.c
index 5e9835ee89..d98246ec75 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -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;
 }
 
diff --git a/tests/virhostcputest.c b/tests/virhostcputest.c
index f935df0f63..c80cd1581c 100644
--- a/tests/virhostcputest.c
+++ b/tests/virhostcputest.c
@@ -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;
 }
-- 
2.31.1




More information about the libvir-list mailing list