]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: use g_auto instead of VIR_FORCE_FCLOSE
authorJán Tomko <jtomko@redhat.com>
Sat, 4 Sep 2021 18:15:29 +0000 (20:15 +0200)
committerJán Tomko <jtomko@redhat.com>
Thu, 9 Sep 2021 16:06:13 +0000 (18:06 +0200)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
tests/securityselinuxlabeltest.c
tests/testutils.c
tests/virhostcputest.c

index f5d7c782bdd48585bcdc6714977f16a313329f3c..a192e86464dddfe1745c638253e4ca8094231547 100644 (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;
 }
 
index 185d281e96c1969c53897db0d6b740ef23417457..1bec5fa8496568e00e40703b9b3696148f4aa081 100644 (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;
 }
 
index f935df0f6369c5c28336c077659788f4487857be..c80cd1581c56cf5bc6e67731904420549f815114 100644 (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;
 }