[glib] Don't call close on invalid fds



commit dc38967fd35286f9489a8cdcb3d811d34113ceca
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Aug 29 15:18:29 2011 -0400

    Don't call close on invalid fds
    
    If an fd is -1, don't call close() on it, since that leads to
    EBDAF and complaints from valgrind.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=657593

 glib/gtestutils.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
---
diff --git a/glib/gtestutils.c b/glib/gtestutils.c
index 623ee12..00bad2b 100644
--- a/glib/gtestutils.c
+++ b/glib/gtestutils.c
@@ -1817,9 +1817,12 @@ g_test_trap_fork (guint64        usec_timeout,
                 }
             }
         }
-      close (stdout_pipe[0]);
-      close (stderr_pipe[0]);
-      close (stdtst_pipe[0]);
+      if (stdout_pipe[0] != -1)
+        close (stdout_pipe[0]);
+      if (stderr_pipe[0] != -1)
+        close (stderr_pipe[0]);
+      if (stdtst_pipe[0] != -1)
+        close (stdtst_pipe[0]);
       if (need_wait)
         {
           int status = 0;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]