Index: sys/kern/kern_descrip.c =================================================================== --- sys/kern/kern_descrip.c (wersja 237198) +++ sys/kern/kern_descrip.c (kopia robocza) @@ -672,7 +672,23 @@ fdrop(fp, td); break; } - /* Check for race with close */ + + /* + * Check for a race with close. + * + * The vnode is now advisory locked (or unlocked, but this case + * is not really important) as the caller requested. + * We had to drop the filedesc lock, so we need to recheck if + * the descriptor is still valid, because if it was closed + * in the meantime we need to remove advisory lock from the + * vnode - close on any descriptor leading to an advisory + * locked vnode, removes that lock. + * We will return 0 on purpose in that case, as the result of + * successful advisory lock might have been externally visible + * already. This is fine - effectively we pretend to the caller + * that the closing thread was a bit slower and that the + * advisory lock succeeded before the close. + */ FILEDESC_SLOCK(fdp); if (fget_locked(fdp, fd) != fp) { FILEDESC_SUNLOCK(fdp);