Document that we're using the current reference instead of incrementing then decrementing the refcount in finishdup().
Ok? Index: kern/kern_descrip.c =================================================================== RCS file: /cvs/src/sys/kern/kern_descrip.c,v retrieving revision 1.147 diff -u -p -r1.147 kern_descrip.c --- kern/kern_descrip.c 9 Apr 2018 13:59:03 -0000 1.147 +++ kern/kern_descrip.c 10 Apr 2018 11:01:45 -0000 @@ -241,6 +241,7 @@ restart: } goto out; } + /* No need for FRELE(), finishdup() uses current ref. */ error = finishdup(p, fp, old, new, retval, 0); out: @@ -320,7 +321,7 @@ restart: panic("dup2: fdalloc"); fd_unused(fdp, new); } - /* finishdup() does FRELE */ + /* No need for FRELE(), finishdup() uses current ref. */ error = finishdup(p, fp, old, new, retval, 1); if (!error && flags & O_CLOEXEC) fdp->fd_ofileflags[new] |= UF_EXCLOSE; @@ -376,7 +377,7 @@ restart: goto restart; } } else { - /* finishdup will FRELE for us. */ + /* No need for FRELE(), finishdup() uses current ref. */ error = finishdup(p, fp, fd, i, retval, 0); if (!error && SCARG(uap, cmd) == F_DUPFD_CLOEXEC) @@ -616,8 +617,6 @@ finishdup(struct proc *p, struct file *f fdp->fd_ofiles[new] = fp; fdp->fd_ofileflags[new] = fdp->fd_ofileflags[old] & ~UF_EXCLOSE; - fp->f_count++; - FRELE(fp, p); if (dup2 && oldfp == NULL) fd_used(fdp, new); *retval = new;