Index: sys/compat/linuxkpi/common/include/linux/file.h =================================================================== --- sys/compat/linuxkpi/common/include/linux/file.h +++ sys/compat/linuxkpi/common/include/linux/file.h @@ -89,7 +89,10 @@ */ fdclose(curthread, file, fd); - /* drop extra reference */ + /* drop reference from fget_unlocked() */ + fdrop(file, curthread); + + /* drop extra reference from falloc() */ fdrop(file, curthread); } @@ -101,12 +104,17 @@ if (fget_unlocked(curthread->td_proc->p_fd, fd, cap_rights_init(&rights), &file, NULL) != 0) { - file = NULL; - } - filp->_file = file; - finit(file, filp->f_mode, DTYPE_DEV, filp, &linuxfileops); + filp->_file = NULL; + } else { + filp->_file = file; + + /* init file */ + finit(file, filp->f_mode, DTYPE_DEV, filp, &linuxfileops); - /* drop the extra reference */ + /* drop the reference from fget_unlocked() */ + fput(filp); + } + /* drop extra reference from falloc() */ fput(filp); } @@ -120,8 +128,6 @@ error = falloc(curthread, &file, &fd, 0); if (error) return -error; - /* drop the extra reference */ - fdrop(file, curthread); return fd; } @@ -135,8 +141,6 @@ error = falloc(curthread, &file, &fd, flags); if (error) return -error; - /* drop the extra reference */ - fdrop(file, curthread); return fd; }