[libvirt PATCH 4/5] tests: commandtest: use VIR_AUTOCLOSE

Ján Tomko jtomko at redhat.com
Tue Jul 28 23:40:47 UTC 2020


Signed-off-by: Ján Tomko <jtomko at redhat.com>
---
 tests/commandtest.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/tests/commandtest.c b/tests/commandtest.c
index a54e467b2b..b0bf6f379a 100644
--- a/tests/commandtest.c
+++ b/tests/commandtest.c
@@ -173,8 +173,8 @@ static int test2(const void *unused G_GNUC_UNUSED)
 static int test3(const void *unused G_GNUC_UNUSED)
 {
     g_autoptr(virCommand) cmd = virCommandNew(abs_builddir "/commandhelper");
-    int newfd1 = dup(STDERR_FILENO);
-    int newfd2 = dup(STDERR_FILENO);
+    VIR_AUTOCLOSE newfd1 = dup(STDERR_FILENO);
+    VIR_AUTOCLOSE newfd2 = dup(STDERR_FILENO);
     int newfd3 = dup(STDERR_FILENO);
     struct stat before, after;
     int ret = -1;
@@ -218,9 +218,6 @@ static int test3(const void *unused G_GNUC_UNUSED)
     ret = checkoutput("test3");
 
  cleanup:
-    /* coverity[double_close] */
-    VIR_FORCE_CLOSE(newfd1);
-    VIR_FORCE_CLOSE(newfd2);
     return ret;
 }
 
@@ -580,7 +577,7 @@ static int test16(const void *unused G_GNUC_UNUSED)
     g_autofree char *outactual = NULL;
     const char *outexpect = "A=B C='D  E' true F 'G  H'";
     int ret = -1;
-    int fd = -1;
+    VIR_AUTOCLOSE fd = -1;
 
     virCommandAddEnvPair(cmd, "A", "B");
     virCommandAddEnvPair(cmd, "C", "D  E");
@@ -610,7 +607,6 @@ static int test16(const void *unused G_GNUC_UNUSED)
     ret = checkoutput("test16");
 
  cleanup:
-    VIR_FORCE_CLOSE(fd);
     return ret;
 }
 
@@ -1039,7 +1035,7 @@ static int test26(const void *unused G_GNUC_UNUSED)
         "wallop";
 
     int ret = -1;
-    int fd = -1;
+    VIR_AUTOCLOSE fd = -1;
 
     virCommandAddEnvPair(cmd, "A", "B");
     virCommandAddEnvPair(cmd, "C", "D  E");
@@ -1071,7 +1067,6 @@ static int test26(const void *unused G_GNUC_UNUSED)
     ret = checkoutput("test26");
 
  cleanup:
-    VIR_FORCE_CLOSE(fd);
     return ret;
 }
 
-- 
2.26.2




More information about the libvir-list mailing list