From 4875c6bbe328dfe666550a3791a6c5362dcb46c7 Mon Sep 17 00:00:00 2001 From: Andrew Webster Date: Fri, 22 Jan 2016 15:59:15 -0600 Subject: [PATCH] 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. --- net/socket/net_close.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/socket/net_close.c b/net/socket/net_close.c index f2a67f78c33..8d657583bd6 100644 --- a/net/socket/net_close.c +++ b/net/socket/net_close.c @@ -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 */