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

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

commit 85b4b25ac3c1d90c5db8d973ebcf7caaa9331bff
Author: dongjiuzhu1 <[email protected]>
AuthorDate: Tue Nov 25 12:18:18 2025 +0800

    net/local: remove extra lock to avoid deadlock
    
    fix logic error
    
    Signed-off-by: dongjiuzhu1 <[email protected]>
---
 net/local/local_connect.c | 58 +++++++++++++++++++++++------------------------
 1 file changed, 28 insertions(+), 30 deletions(-)

diff --git a/net/local/local_connect.c b/net/local/local_connect.c
index b6e1d1e532c..1266afc7e2c 100644
--- a/net/local/local_connect.c
+++ b/net/local/local_connect.c
@@ -149,9 +149,7 @@ errout_with_outfd:
 errout_with_conn:
   local_release_fifos(conn);
   client->lc_state = LOCAL_STATE_BOUND;
-  local_lock();
   local_free(conn);
-  local_unlock();
 
   return ret;
 }
@@ -244,45 +242,45 @@ int psock_local_connect(FAR struct socket *psock,
 
       switch (conn->lc_type)
         {
-        case LOCAL_TYPE_UNNAMED:   /* A Unix socket that is not bound to any 
name */
-          break;
+          case LOCAL_TYPE_UNNAMED:   /* A Unix socket that is not bound to any 
name */
+            break;
 
-        case LOCAL_TYPE_ABSTRACT:  /* lc_path is length zero */
-        case LOCAL_TYPE_PATHNAME:  /* lc_path holds a null terminated string */
+          case LOCAL_TYPE_ABSTRACT:  /* lc_path is length zero */
+          case LOCAL_TYPE_PATHNAME:  /* lc_path holds a null terminated string 
*/
 
-          /* Anything in the listener list should be a stream socket in the
-           * listening state
-           */
+            /* Anything in the listener list should be a stream socket in the
+             * listening state
+             */
 
-          if (conn->lc_state == LOCAL_STATE_LISTENING &&
-              conn->lc_type == type && conn->lc_proto == SOCK_STREAM &&
-              strncmp(conn->lc_path, unpath, UNIX_PATH_MAX - 1) == 0)
-            {
-              /* Bind the address and protocol */
+            if (conn->lc_state == LOCAL_STATE_LISTENING &&
+                conn->lc_type == type && conn->lc_proto == SOCK_STREAM &&
+                strncmp(conn->lc_path, unpath, UNIX_PATH_MAX - 1) == 0)
+              {
+                /* Bind the address and protocol */
 
-              client->lc_type  = conn->lc_type;
-              client->lc_proto = conn->lc_proto;
-              client->lc_instance_id = local_generate_instance_id();
+                client->lc_type  = conn->lc_type;
+                client->lc_proto = conn->lc_proto;
+                client->lc_instance_id = local_generate_instance_id();
 
-              /* The client is now bound to an address */
+                /* The client is now bound to an address */
 
-              client->lc_state = LOCAL_STATE_BOUND;
+                client->lc_state = LOCAL_STATE_BOUND;
 
-              /* We have to do more for the SOCK_STREAM family */
+                /* We have to do more for the SOCK_STREAM family */
 
-              ret = local_stream_connect(client, conn,
-                          _SS_ISNONBLOCK(client->lc_conn.s_flags));
+                ret = local_stream_connect(client, conn,
+                            _SS_ISNONBLOCK(client->lc_conn.s_flags));
 
-              local_unlock();
-              return ret;
-            }
+                local_unlock();
+                return ret;
+              }
 
-          break;
+            break;
 
-        default:        /* Bad, memory must be corrupted */
-          DEBUGPANIC(); /* PANIC if debug on */
-          local_unlock();
-          return -EINVAL;
+          default:        /* Bad, memory must be corrupted */
+            DEBUGPANIC(); /* PANIC if debug on */
+            local_unlock();
+            return -EINVAL;
         }
     }
 

Reply via email to