1 #include <unistd.h> 2 #include <fcntl.h> 3 #include "fdleak.h" 4 main(int argc,char ** argv)5int main (int argc, char **argv) 6 { 7 int s1; 8 int s2; 9 10 CLOSE_INHERITED_FDS; 11 12 s1 = DO( open("/dev/null", O_RDONLY) ); 13 s2 = DO( open("/dev/null", O_RDONLY) ); 14 15 (void) DO( dup2(s1, 20) ); // dup s1 as fd 20 16 (void) DO( dup2(s1, s2) ); // dup s1 as fd s2, which closes existing s2 fd 17 18 return 0; 19 } 20