Open GoogleCodeExporter opened 8 years ago
I don't think anything needs to be done here.
Upon calling exec(), we have to close all file handles except for the ones that
we intentionally want to pass to the newly launched child process. In Advanced
Programming in the UNIX Environment, Stevens suggests closing all possible file
handles. This can be done by looping from 3 to sysconf(OPEN_MAX).
Historically, this was good advice as a) there was no way to determine the list
of open file handles, and b) OPEN_MAX was typically pretty small (on the order
of a few hundred). So, the cost of making these system calls was cheap.
These days, OPEN_MAX is on the order of thousands or tens of thousands. Making
this many calls to close() results in noticeable delays. So, if at all
possible, it is more efficient to only close the file handles that are actually
open. On Linux, this can be achieved by enumerating the entries in
/proc/self/fd.
In either case, we'll trigger a false positive in valgrind. Valgrind opens a
few file handles for internal use, and since we have no way of telling that we
should be skipping these file handles, we'll attempt to close them.
I believe, Valgrind notices and actually prevents us from doing so. So, no
actual harm done. But we still get a warning message.
The correct thing to do is to ignore the warning, if it triggers as part of
closeAllFds(). If it triggers anywhere else, we of course want to investigate.
If you feel particularly bothered by this, you should try to come up with a
valgrind suppression file. That's actually the right thing to do here.
Original comment by zod...@gmail.com
on 6 Apr 2012 at 4:23
Original issue reported on code.google.com by
beewoo...@gmail.com
on 6 Apr 2012 at 3:25