Skip to content

Commit

Permalink
net/tcp: discard connect reference before free
Browse files Browse the repository at this point in the history
connect reference should be set to 0 before free

Signed-off-by: chao.an <[email protected]>
  • Loading branch information
anchao authored and xiaoxiang781216 committed Jul 2, 2022
1 parent bd713d6 commit b88a1fd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion net/tcp/tcp_close.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 */

Expand Down
1 change: 1 addition & 0 deletions net/tcp/tcp_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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! */
Expand Down

0 comments on commit b88a1fd

Please sign in to comment.