[compiler-rt] [sanitizer] Use close_range on Linux to close FDs in StartSubprocess (PR #191450)

Paweł Bylica via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 13 23:59:07 PDT 2026


================
@@ -562,11 +562,15 @@ pid_t StartSubprocess(const char *program, const char *const argv[],
       internal_close(stderr_fd);
     }
 
-#  if SANITIZER_FREEBSD
-    internal_close_range(3, ~static_cast<fd_t>(0), 0);
-#  else
-    for (int fd = sysconf(_SC_OPEN_MAX); fd > 2; fd--) internal_close(fd);
+#  if SANITIZER_FREEBSD || SANITIZER_LINUX
+    // Use close_range (FreeBSD 13+, Linux 5.9+) to avoid a slow loop
+    // when RLIMIT_NOFILE is high (e.g. 1B in Docker environments).
+    // Falls back to the loop if the syscall is not available.
+    if (internal_close_range(3, ~static_cast<fd_t>(0), 0) != 0)
----------------
chfast wrote:

Done in https://github.com/llvm/llvm-project/pull/191971.

https://github.com/llvm/llvm-project/pull/191450


More information about the llvm-commits mailing list