TCP: check for connection before deleting it

It is possible for a socket to have no connection, for example if a TCP
socket is waiting in accept.  This checks for this condition in case the
socket is closed from a different thread.
This commit is contained in:
Andrew Webster
2016-01-22 15:59:15 -06:00
committed by Gregory Nutt
parent f1ef2c6cde
commit 4875c6bbe3
+4 -1
View File
@@ -524,9 +524,12 @@ int psock_close(FAR struct socket *psock)
/* We perform the uIP close operation only if this is the last count on
* the socket. (actually, I think the socket crefs only takes the values
* 0 and 1 right now).
*
* It is possible for a psock to have no connection, e.g. a TCP socket
* waiting in accept.
*/
if (psock->s_crefs <= 1)
if (psock->s_crefs <= 1 && psock->s_conn != NULL)
{
/* Perform uIP side of the close depending on the protocol type */