diff --git a/net/tcp/tcp_close.c b/net/tcp/tcp_close.c index 2f5f8599fe..b3a81a80ce 100644 --- a/net/tcp/tcp_close.c +++ b/net/tcp/tcp_close.c @@ -58,10 +58,6 @@ static void tcp_close_work(FAR void *param) /* Stop the network monitor for all sockets */ tcp_stop_monitor(conn, TCP_CLOSE); - - /* Discard our reference to the connection */ - - conn->crefs = 0; tcp_free(conn); net_unlock(); @@ -360,6 +356,7 @@ int tcp_close(FAR struct socket *psock) /* Perform the disconnection now */ tcp_unlisten(conn); /* No longer accepting connections */ + conn->crefs = 0; /* Discard our reference to the connection */ /* Break any current connections and close the socket */ diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c index 34ac2f9387..aad46069a5 100644 --- a/net/tcp/tcp_conn.c +++ b/net/tcp/tcp_conn.c @@ -696,7 +696,6 @@ FAR struct tcp_conn_s *tcp_alloc(uint8_t domain) * waiting for it. */ - conn->crefs = 0; tcp_free(conn); /* Now there is guaranteed to be one free connection. Get it! */