]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
tests fdleak.h close all open file descriptors > 2
authorMark Wielaard <mark@klomp.org>
Fri, 14 Apr 2023 22:13:57 +0000 (00:13 +0200)
committerMark Wielaard <mark@klomp.org>
Fri, 14 Apr 2023 22:14:01 +0000 (00:14 +0200)
Use sysconf (_SC_OPEN_MAX) to find the upper limit. Or use 1024
if that fails.

https://bugs.kde.org/show_bug.cgi?id=467714

NEWS
none/tests/fdleak.h

diff --git a/NEWS b/NEWS
index 13efee7d4a5035e0ed6800b623d1b0a998df1fe4..6d93d2603ea27079314caa6e7485c8826cd97ffe 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -147,6 +147,8 @@ are not entered into bugzilla tend to get forgotten about or ignored.
 465435  m_libcfile.c:66 (vgPlain_safe_fd): Assertion 'newfd >= VG_(fd_hard_limit)' failed.
 466104  aligned_alloc problems, part 1
 467482  Build failure on aarch64 Alpine
+467714  fdleak_* and rlimit tests fail when parent process has more than
+        64 descriptors opened
 467839  Gdbserver: Improve compatibility of library directory name
 n-i-bz  FreeBSD rfork syscall fail with EINVAL or ENOSYS rather than VG_(unimplemented)
 
index 66fd84e96f7539ecafae3e7c84addd77efe313b6..c94dbde3197896b042b257f3b6ce2a7c527c2b4a 100644 (file)
@@ -2,6 +2,7 @@
 #define _FDLEAK_H_
 
 #include <stdlib.h>
+#include <unistd.h>
 #include <stdio.h>
 
 #define DO(op) \
  * - For Ubuntu 8.04, see also
  *   https://bugs.launchpad.net/ubuntu/+source/seahorse/+bug/235184
  */
-#define CLOSE_INHERITED_FDS { int i; for (i = 3; i < 64; i++) close(i); }
+static inline void close_inherited () {
+   int i; int max_fds = sysconf (_SC_OPEN_MAX);
+   if (max_fds < 0)
+      max_fds = 1024; /* Fallback if sysconf fails, returns -1.  */
+
+   /* Only leave 0 (stdin), 1 (stdout) and 2 (stderr) open.  */
+   for (i = 3; i < max_fds; i++)
+      close(i);
+}
+#define CLOSE_INHERITED_FDS close_inherited ()
 
 #endif /* _FDLEAK_H_ */