Hi bluhm, I don't think need "if (fd > STDERR_FILENO)" cause the fd is a new opened file descriptor. If its value is less or equal than `STDERR_FILENO', it means the stdin or stderr is already closed intentionally. So it should be OK close fd again.
Thanks! On 9/8/2018 8:26 PM, Alexander Bluhm wrote: > On Sat, Sep 08, 2018 at 11:05:15AM +0800, Nan Xiao wrote: >> The following patch fixes file descriptor leak in `dofile' function. >> Sorry if I am wrong, thanks! > > It is a leak. > >> @@ -125,6 +125,7 @@ dupit: >> (void)lseek(fd, (off_t)0, SEEK_END); >> if (dup2(fd, STDOUT_FILENO) == -1) >> err(EXIT_MISC, NULL); > > The paranoid would put an if (fd > STDERR_FILENO) here. > >> + (void)close(fd); >> (void)fprintf(stderr, "sending output to %s\n", p); >> } > > bluhm > -- Best Regards Nan Xiao(肖楠)
