anchao commented on a change in pull request #3895:
URL: https://github.com/apache/incubator-nuttx/pull/3895#discussion_r649718984
##########
File path: fs/socket/socket.c
##########
@@ -285,6 +284,9 @@ int socket(int domain, int type, int protocol)
errout_with_sockfd:
nx_close(sockfd);
Review comment:
Done
##########
File path: net/socket/accept.c
##########
@@ -259,29 +260,36 @@ int accept(int sockfd, FAR struct sockaddr *addr, FAR
socklen_t *addrlen)
goto errout;
}
- /* Allocate a socket descriptor for the new connection now (so that it
- * cannot fail later)
- */
-
- newfd = sockfd_allocate(&newsock, O_RDWR);
- if (newfd < 0)
+ newsock = kmm_zalloc(sizeof(*newsock));
+ if (newsock == NULL)
{
- errcode = ENFILE;
+ errcode = ENOMEM;
goto errout;
}
ret = psock_accept(psock, addr, addrlen, newsock);
if (ret < 0)
{
errcode = -ret;
- goto errout_with_socket;
+ goto errout_with_alloc;
+ }
+
+ /* Allocate a socket descriptor for the new connection now (so that it
+ * cannot fail later)
+ */
+
+ newfd = sockfd_allocate(newsock, O_RDWR);
+ if (newfd < 0)
+ {
+ errcode = ENFILE;
+ goto errout_with_alloc;
}
leave_cancellation_point();
return newfd;
-errout_with_socket:
- nx_close(newfd);
+errout_with_alloc:
+ kmm_free(newsock);
Review comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]