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

            Bug ID: 432508
           Summary: Valgrind does not honor setrlimit RLIMIT_NOFILE
                    changes
           Product: valgrind
           Version: 3.15 SVN
          Platform: Other
                OS: Linux
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: general
          Assignee: jsew...@acm.org
          Reporter: bal...@balintreczey.hu
  Target Milestone: ---

SUMMARY

Valgrind uses open file limits in effect when valgrind starts, ignoring the
changes made my the debugged program.

STEPS TO REPRODUCE

$ cat many-files.c
#include <assert.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>

int main (int argc, char ** argv) {
  int i;
  struct rlimit rlim;
  getrlimit(RLIMIT_NOFILE, &rlim);
  assert(rlim.rlim_cur <= 1024);

  rlim.rlim_cur = 2048;
  setrlimit(RLIMIT_NOFILE, &rlim);

  for (i = 4; i < 1028; i++) {
    dup2(1, i);
  }
  for (i = 4; i < 1028; i++) {
    close(i);
  }
  return 1;
}
$ gcc many-files.c
$ valgrind ./a.out

OBSERVED RESULT

==3814075== Memcheck, a memory error detector
==3814075== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==3814075== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==3814075== Command: ./a.out
==3814075== 
==3814075== Warning: invalid file descriptor 1024 in syscall dup2()
==3814075== Warning: invalid file descriptor 1025 in syscall dup2()
==3814075== Warning: invalid file descriptor 1026 in syscall dup2()
==3814075== Warning: invalid file descriptor 1027 in syscall dup2()
==3814075==    Use --log-fd=<number> to select an alternative log fd.
==3814075== Warning: invalid file descriptor 1024 in syscall close()
==3814075== Warning: invalid file descriptor 1025 in syscall close()
==3814075== Warning: invalid file descriptor 1026 in syscall close()
==3814075== Warning: invalid file descriptor 1027 in syscall close()
==3814075==    Use --log-fd=<number> to select an alternative log fd.
==3814075== 
==3814075== HEAP SUMMARY:
==3814075==     in use at exit: 0 bytes in 0 blocks
==3814075==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==3814075== 
==3814075== All heap blocks were freed -- no leaks are possible
==3814075== 
==3814075== For lists of detected and suppressed errors, rerun with: -s
==3814075== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)


EXPECTED RESULT

Valgrind notices RLIMIT_NOFILE changes and uses the new limit in fd validity
check.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Ubuntu 20.04
Valgrind: valgrind-3.15.0

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to