if (!(file = fcheck(oldfd)))
goto out_unlock;
err = newfd;
- if (newfd == oldfd)
+ if (unlikely(newfd == oldfd)) {
+ if (flags & O_CLOEXEC) {
+ fdt = files_fdtable(files);
+ FD_SET(newfd, fdt->close_on_exec);
+ }
goto out_unlock;
+ }
err = -EBADF;
if (newfd >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
goto out_unlock;