|
From: Nigel H. <nj...@ba...> - 2006-08-13 17:07:54
Attachments:
njh.vcf
|
1. create this file:
main()
{
close(15);
}
2. cc -g foo.c
3. valgrind --tool=memcheck --num-callers=20 --leak-check=yes
--track-fds=yes ./a.out
Since file descriptors are being tracked, it would be useful to warn of
closing files that aren't open, perhaps --warn-close-fds=yes
-Nigel
|
|
From: Paul P. <ppl...@gm...> - 2006-08-13 17:40:26
|
Nigel Horne wrote: > Since file descriptors are being tracked, it would be useful to warn of > closing files that aren't open, perhaps --warn-close-fds=yes You don't need something as advanced as VG for this. Simple "strace -etrace=close ./a.out 2>&1 | grep EBADF" will do. Note however, that it is somewhat common UNIX practice to close FDs that aren't open, and you are likely to encounter such code in various libraries (it's often easier to just close FD again, rather than keep track of whether it's currently open or not). Cheers, |
|
From: Nigel H. <nj...@ba...> - 2006-08-13 17:43:20
Attachments:
njh.vcf
|
Paul Pluzhnikov wrote: > Nigel Horne wrote: > >> Since file descriptors are being tracked, it would be useful to warn of >> closing files that aren't open, perhaps --warn-close-fds=yes > > You don't need something as advanced as VG for this. > Simple "strace -etrace=close ./a.out 2>&1 | grep EBADF" will do. No it won't do, since it doesn't tell you where the errant close is, all you get is: close(15) = -1 EBADF (Bad file descriptor) -Nigel |
|
From: Nicholas N. <nj...@cs...> - 2006-08-14 00:54:29
|
On Sun, 13 Aug 2006, Paul Pluzhnikov wrote:
> Nigel Horne wrote:
>
>> Since file descriptors are being tracked, it would be useful to warn of
>> closing files that aren't open, perhaps --warn-close-fds=yes
>
> You don't need something as advanced as VG for this.
> Simple "strace -etrace=close ./a.out 2>&1 | grep EBADF" will do.
>
> Note however, that it is somewhat common UNIX practice to
> close FDs that aren't open, and you are likely to encounter
> such code in various libraries (it's often easier to just
> close FD again, rather than keep track of whether it's
> currently open or not).
Yes, many programs do something not much more sophisticated than this:
for (i = 0; i < BIG_NUMBER; i++)
close(i);
Nick
|
|
From: Behdad E. <bes...@re...> - 2006-08-14 03:59:17
|
On Mon, 2006-08-14 at 10:46 +1000, Nicholas Nethercote wrote: > On Sun, 13 Aug 2006, Paul Pluzhnikov wrote: >=20 > > Nigel Horne wrote: > > > >> Since file descriptors are being tracked, it would be useful to warn o= f > >> closing files that aren't open, perhaps --warn-close-fds=3Dyes > > > > You don't need something as advanced as VG for this. > > Simple "strace -etrace=3Dclose ./a.out 2>&1 | grep EBADF" will do. > > > > Note however, that it is somewhat common UNIX practice to > > close FDs that aren't open, and you are likely to encounter > > such code in various libraries (it's often easier to just > > close FD again, rather than keep track of whether it's > > currently open or not). >=20 > Yes, many programs do something not much more sophisticated than this: >=20 > for (i =3D 0; i < BIG_NUMBER; i++) > close(i); >=20 > Nick That's kind of a dumb case of it, still popular. A more sophisticated and common use is to do something like this in daemons: close (0); close (1); close (2); --=20 behdad http://behdad.org/ |
|
From: Nigel H. <nj...@ba...> - 2006-08-14 07:02:59
Attachments:
njh.vcf
|
Behdad Esfahbod wrote: > On Mon, 2006-08-14 at 10:46 +1000, Nicholas Nethercote wrote: >> On Sun, 13 Aug 2006, Paul Pluzhnikov wrote: >> >>> Nigel Horne wrote: >>> >>>> Since file descriptors are being tracked, it would be useful to warn of >>>> closing files that aren't open, perhaps --warn-close-fds=yes >>> You don't need something as advanced as VG for this. >>> Simple "strace -etrace=close ./a.out 2>&1 | grep EBADF" will do. >>> >>> Note however, that it is somewhat common UNIX practice to >>> close FDs that aren't open, and you are likely to encounter >>> such code in various libraries (it's often easier to just >>> close FD again, rather than keep track of whether it's >>> currently open or not). >> Yes, many programs do something not much more sophisticated than this: >> >> for (i = 0; i < BIG_NUMBER; i++) >> close(i); >> >> Nick > > That's kind of a dumb case of it, still popular. A more sophisticated > and common use is to do something like this in daemons: > > close (0); > close (1); > close (2); No-one would force those programmers to use the --warn-close-fds=yes option. -Nigel |
|
From: Paul P. <ppl...@gm...> - 2006-08-13 17:50:03
|
Nigel Horne wrote: > No it won't do, since it doesn't tell you where the errant close is, > all you get is: > > close(15) = -1 EBADF (Bad file descriptor) Once you know there is a "bad close", it is trivial to find where it comes from (just use 'gdb'). VG gives you huge advantage for bugs that are *hard* to find. The one in your example isn't (just MHO). Cheers, |
|
From: Nigel H. <nj...@ba...> - 2006-08-13 19:24:09
Attachments:
njh.vcf
|
Paul Pluzhnikov wrote: > Nigel Horne wrote: > >> No it won't do, since it doesn't tell you where the errant close is, >> all you get is: >> >> close(15) = -1 EBADF (Bad file descriptor) > > Once you know there is a "bad close", it is trivial to find where > it comes from (just use 'gdb'). > > VG gives you huge advantage for bugs that are *hard* to find. > The one in your example isn't (just MHO). Of course, that's what an example is for - to explain the point not to show buggy code. > Cheers, |