You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/07/02 08:07:39 UTC

[incubator-nuttx] branch master updated: net/tcp: discard connect reference before free

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new b88a1fd7fd net/tcp: discard connect reference before free
b88a1fd7fd is described below

commit b88a1fd7fdf713f7c653453f40094e3e98b2ff6c
Author: chao.an <an...@xiaomi.com>
AuthorDate: Sat Jul 2 13:17:41 2022 +0800

    net/tcp: discard connect reference before free
    
    connect reference should be set to 0 before free
    
    Signed-off-by: chao.an <an...@xiaomi.com>
---
 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 b3a81a80ce..2f5f8599fe 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 aad46069a5..34ac2f9387 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! */