diff --git a/net/socket/net_sockets.c b/net/socket/net_sockets.c index d6523ed61c..233d48e2b7 100644 --- a/net/socket/net_sockets.c +++ b/net/socket/net_sockets.c @@ -40,7 +40,6 @@ #include #include -#include #include #include #include @@ -48,6 +47,7 @@ #include #include +#include #include "socket/socket.h" @@ -192,30 +192,19 @@ void psock_release(FAR struct socket *psock) { if (psock != NULL) { - /* Take the list semaphore so that there will be no accesses - * to this socket structure. + /* Decrement the count if there the socket will persist + * after this. */ - FAR struct socketlist *list = sched_getsockets(); - if (list) + if (psock->s_crefs > 1) { - /* Decrement the count if there the socket will persist - * after this. - */ + psock->s_crefs--; + } + else + { + /* The socket will not persist... reset it */ - _net_semtake(list); - if (psock->s_crefs > 1) - { - psock->s_crefs--; - } - else - { - /* The socket will not persist... reset it */ - - memset(psock, 0, sizeof(struct socket)); - } - - _net_semgive(list); + memset(psock, 0, sizeof(struct socket)); } } } @@ -240,11 +229,19 @@ void sockfd_release(int sockfd) FAR struct socket *psock = sockfd_socket(sockfd); - /* Get the socket structure for this sockfd */ - if (psock) { - psock_release(psock); + /* Take the list semaphore so that there will be no accesses + * to this socket structure. + */ + + FAR struct socketlist *list = sched_getsockets(); + if (list) + { + _net_semtake(list); + psock_release(psock); + _net_semgive(list); + } } }