Then, it would be tempting to take the dup(fd,0); close(fd); out to before the if(pid==0)...
probably the file descriptor leak comes from dnresolve.c