From b88a1fd7fdf713f7c653453f40094e3e98b2ff6c Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Sat, 2 Jul 2022 13:17:41 +0800 Subject: [PATCH] net/tcp: discard connect reference before free connect reference should be set to 0 before free Signed-off-by: chao.an --- net/tcp/tcp_close.c | 5 ++++- net/tcp/tcp_conn.c | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/net/tcp/tcp_close.c b/net/tcp/tcp_close.c index b3a81a80ce9de..2f5f8599fefd3 100644 --- a/net/tcp/tcp_close.c +++ b/net/tcp/tcp_close.c @@ -58,6 +58,10 @@ 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(); @@ -356,7 +360,6 @@ 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 aad46069a52d3..34ac2f9387fa6 100644 --- a/net/tcp/tcp_conn.c +++ b/net/tcp/tcp_conn.c @@ -696,6 +696,7 @@ 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! */