diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 61e13c1..6cdf5b5 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -1461,7 +1461,7 @@ fdalloc(struct thread *td, int minfd, int *result) { struct proc *p = td->td_proc; struct filedesc *fdp = p->p_fd; - int fd = -1, maxfd; + int fd = -1, maxfd, allocfd; #ifdef RACCT int error; #endif @@ -1484,15 +1484,16 @@ fdalloc(struct thread *td, int minfd, int *result) if (fd >= maxfd) return (EMFILE); if (fd >= fdp->fd_nfiles) { + allocfd = 2 * max(fdp->fd_nfiles, fd); #ifdef RACCT PROC_LOCK(p); error = racct_set(p, RACCT_NOFILE, - min(fdp->fd_nfiles * 2, maxfd)); + min(allocfd, maxfd)); PROC_UNLOCK(p); if (error != 0) return (EMFILE); #endif - fdgrowtable(fdp, min(fdp->fd_nfiles * 2, maxfd)); + fdgrowtable(fdp, min(allocfd, maxfd)); /* Retry... */ fd = fd_first_free(fdp, minfd, fdp->fd_nfiles); if (fd >= maxfd)