| Summary: | fdleak_* and rlimit tests fail when parent process has more than 64 descriptors opened. | ||
|---|---|---|---|
| Product: | [Developer tools] valgrind | Reporter: | Jesus Checa <jcheca> |
| Component: | general | Assignee: | Mark Wielaard <mark> |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | CC: | mark |
| Priority: | NOR | ||
| Version First Reported In: | 3.19.0 | ||
| Target Milestone: | --- | ||
| Platform: | Other | ||
| OS: | Linux | ||
| Latest Commit: | Version Fixed/Implemented In: | ||
| Sentry Crash Report: | |||
| Attachments: | close all file descriptors > 2 with CLOSE_INHERITED_FDS | ||
Created attachment 157527 [details]
close all file descriptors > 2 with CLOSE_INHERITED_FDS
Tested with:
#include <stdlib.h>
#include <unistd.h>
int main (int argc, char *const argv[])
{
for (int i = 0; i < 100; ++i)
dup (1);
execvp (argv[1], argv + 1);
exit (1);
}
gcc -o dup100 dup100.c
./dup100 valgrind --track-fds=yes /bin/true
==673839== FILE DESCRIPTORS: 103 open (3 std) at exit.
==673839== Open file descriptor 102: /dev/pts/5
==673839== <inherited from parent>
[...]
./dup100 perl tests/vg_regtest none/tests/fdleak*vgtest
all fail
with patch all succeed
\o/
commit 16be0ca4ba53154642bd45e6aa60ffba57369a0c Author: Mark Wielaard <mark@klomp.org> Date: Sat Apr 15 00:13:57 2023 +0200 tests fdleak.h close all open file descriptors > 2 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 |
We found out that none/tests/fdleak_* and note/tests/rlimit{,64}_nofile tests fail if the parent process has more than 64 opened file descriptors. These tests starts by closing all the inherited descriptors to have a known state at start/end of the test by calling. However this macro only closes the range [3,64] as defined in none/tests/fdleak.h: #define CLOSE_INHERITED_FDS { int i; for (i = 3; i < 64; i++) close(i); } It would be great to close up to MAXFDS instead.