diff -NurpP --minimal a/fs/fcntl.c b/fs/fcntl.c --- a/fs/fcntl.c 2005-01-23 12:21:08.000000000 +0100 +++ b/fs/fcntl.c 2005-01-23 00:52:23.000000000 +0100 @@ -191,10 +191,12 @@ asmlinkage long sys_dup2(unsigned int ol FD_SET(newfd, files->open_fds); FD_CLR(newfd, files->close_on_exec); spin_unlock(&files->file_lock); - vx_openfd_inc(newfd); if (tofree) filp_close(tofree, files); + else + vx_openfd_inc(newfd); /* fd was unused */ + err = newfd; out: return err;