Skip to content

Commit

Permalink
reorder alloc_fd/attach_fd in socketpair()
Browse files Browse the repository at this point in the history
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
  • Loading branch information
Al Viro committed Dec 16, 2009
1 parent 7327412 commit 198de4d
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions net/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -1396,23 +1396,30 @@ SYSCALL_DEFINE4(socketpair, int, family, int, type, int, protocol,
goto out_release_both;
}

fd2 = sock_alloc_fd(&newfile2, flags & O_CLOEXEC);
if (unlikely(fd2 < 0)) {
err = fd2;
err = sock_attach_fd(sock1, newfile1, flags & O_NONBLOCK);
if (unlikely(err < 0)) {
put_filp(newfile1);
put_unused_fd(fd1);
goto out_release_both;
}

err = sock_attach_fd(sock1, newfile1, flags & O_NONBLOCK);
if (unlikely(err < 0)) {
goto out_fd2;
fd2 = sock_alloc_fd(&newfile2, flags & O_CLOEXEC);
if (unlikely(fd2 < 0)) {
err = fd2;
fput(newfile1);
put_unused_fd(fd1);
sock_release(sock2);
goto out;
}

err = sock_attach_fd(sock2, newfile2, flags & O_NONBLOCK);
if (unlikely(err < 0)) {
put_filp(newfile2);
put_unused_fd(fd2);
fput(newfile1);
goto out_fd1;
put_unused_fd(fd1);
sock_release(sock2);
goto out;
}

audit_fd_pair(fd1, fd2);
Expand All @@ -1438,16 +1445,6 @@ SYSCALL_DEFINE4(socketpair, int, family, int, type, int, protocol,
sock_release(sock1);
out:
return err;

out_fd2:
put_filp(newfile1);
sock_release(sock1);
out_fd1:
put_filp(newfile2);
sock_release(sock2);
put_unused_fd(fd1);
put_unused_fd(fd2);
goto out;
}

/*
Expand Down

0 comments on commit 198de4d

Please sign in to comment.