You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/06/11 10:00:29 UTC

[incubator-nuttx] 02/02: net/accept: alloc the accept fd after accept success

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit b6bf9cf44b417fd8b10c88159b603ee5230118a6
Author: chao.an <an...@xiaomi.com>
AuthorDate: Fri Jun 11 12:24:37 2021 +0800

    net/accept: alloc the accept fd after accept success
    
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 net/socket/accept.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/net/socket/accept.c b/net/socket/accept.c
index 08107d9..2431285 100644
--- a/net/socket/accept.c
+++ b/net/socket/accept.c
@@ -267,6 +267,13 @@ int accept(int sockfd, FAR struct sockaddr *addr, FAR socklen_t *addrlen)
       goto errout;
     }
 
+  ret = psock_accept(psock, addr, addrlen, newsock);
+  if (ret < 0)
+    {
+      errcode = -ret;
+      goto errout_with_alloc;
+    }
+
   /* Allocate a socket descriptor for the new connection now (so that it
    * cannot fail later)
    */
@@ -275,21 +282,14 @@ int accept(int sockfd, FAR struct sockaddr *addr, FAR socklen_t *addrlen)
   if (newfd < 0)
     {
       errcode = ENFILE;
-      goto errout_with_alloc;
-    }
-
-  ret = psock_accept(psock, addr, addrlen, newsock);
-  if (ret < 0)
-    {
-      errcode = -ret;
-      goto errout_with_socket;
+      goto errout_with_psock;
     }
 
   leave_cancellation_point();
   return newfd;
 
-errout_with_socket:
-  nx_close(newfd);
+errout_with_psock:
+  psock_close(newsock);
 
 errout_with_alloc:
   kmm_free(newsock);