The branch main has been updated by mjg:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=809f3121be660ac9f0605dd347b41b1b5e9ab195

commit 809f3121be660ac9f0605dd347b41b1b5e9ab195
Author:     Mateusz Guzik <[email protected]>
AuthorDate: 2022-01-29 22:12:42 +0000
Commit:     Mateusz Guzik <[email protected]>
CommitDate: 2022-02-13 13:07:08 +0000

    fd: assign fd_freefile early when copying
    
    This is to simplify an upcomming change.
---
 sys/kern/kern_descrip.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index 1dc0f1e647d6..feb35c28cba1 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -2356,13 +2356,13 @@ fdcopy(struct filedesc *fdp)
                FILEDESC_SLOCK(fdp);
        }
        /* copy all passable descriptors (i.e. not kqueue) */
-       newfdp->fd_freefile = -1;
+       newfdp->fd_freefile = fdp->fd_freefile;
        for (i = 0; i <= lastfile; ++i) {
                ofde = &fdp->fd_ofiles[i];
                if (ofde->fde_file == NULL ||
                    (ofde->fde_file->f_ops->fo_flags & DFLAG_PASSABLE) == 0 ||
                    !fhold(ofde->fde_file)) {
-                       if (newfdp->fd_freefile == -1)
+                       if (newfdp->fd_freefile == fdp->fd_freefile)
                                newfdp->fd_freefile = i;
                        continue;
                }
@@ -2371,8 +2371,7 @@ fdcopy(struct filedesc *fdp)
                filecaps_copy(&ofde->fde_caps, &nfde->fde_caps, true);
                fdused_init(newfdp, i);
        }
-       if (newfdp->fd_freefile == -1)
-               newfdp->fd_freefile = i;
+       MPASS(newfdp->fd_freefile != -1);
        FILEDESC_SUNLOCK(fdp);
        return (newfdp);
 }

Reply via email to