With valgrind 3.25.0 the following shows the FILE DESCRIPTORS banner, when it shouldn't $ valgrind -q --track-fds=yes cat /dev/null ==1937149== FILE DESCRIPTORS: 1 open (3 inherited) at exit. ==1937149== cat (coreutils) closes stdout and stderr before exit. The still open file descriptor is stdin. Note that it still says 3 inherited. The problem is that the check whether or not to show the banner is: (fd_count - inherited == 0) The fix seems to be to check whether the inherited file descriptors are already closed: diff --git a/coregrind/m_syswrap/syswrap-generic.c b/coregrind/m_syswrap/syswrap-generic.c index 82a682a5ce55..81c8fc028d88 100644 --- a/coregrind/m_syswrap/syswrap-generic.c +++ b/coregrind/m_syswrap/syswrap-generic.c @@ -987,7 +987,7 @@ void VG_(show_open_fds) (const HChar* when) int inherited = 0; for (i = allocated_fds; i; i = i->next) { - if (i->where == NULL) + if (i->where == NULL && !i->fd_closed) inherited++; }
commit 29a5fcb3f6371584f89f9b54c793cc0f29802553 Author: Mark Wielaard <mark@klomp.org> Date: Wed May 14 00:13:06 2025 +0200 Don't count closed inherited file descriptors Programs which close some inherited file descriptors and are run under valgrind with -q and --track-fds=yes would still show the FILE DESCRIPTORS banner even if there were no non-inherited file descriptors still open. Fix this by not counting already closed inherited file descriptors. Add a simple testcase to show /usr/bin/cat /dev/null doesn't produce any output running under valgrind -q --track-fds=yes. https://bugs.kde.org/show_bug.cgi?id=504177