From f23723c5581c93c49c5ee81315f2b29b06362469 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E5=AD=99=E6=98=A5=E9=98=B3?= Date: Wed, 31 Dec 2025 12:51:36 +0800 Subject: [PATCH] =?utf8?q?=E8=A1=A5=E5=85=85=E4=BF=AE=E5=A4=8Dlwip=20?= =?utf8?q?=E7=BD=91=E7=BB=9C=E6=81=A2=E5=A4=8D=E6=AD=BB=E6=9C=BAbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../lwip/lwip_v2.1.3/src/api/api_msg.c | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/api/api_msg.c b/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/api/api_msg.c index 2a83cfa24..8bef06c78 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/api/api_msg.c +++ b/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/api/api_msg.c @@ -1945,20 +1945,26 @@ err_mem: /* everything was written: set back connection state and back to application task */ /* Re-check current_msg validity before accessing it (err_tcp may have cleared it) */ - if (conn->current_msg != NULL) { - /* Normal cleanup: current_msg is still valid, so we need to clean up */ - sys_sem_t *op_completed_sem = LWIP_API_MSG_SEM(conn->current_msg); - conn->current_msg->err = err; - /* Reset state BEFORE clearing current_msg to avoid race condition: - * If poll_tcp/sent_tcp is called between these two assignments, - * we want state to be NETCONN_NONE (not NETCONN_WRITE) when current_msg is NULL */ - conn->state = NETCONN_NONE; - conn->current_msg = NULL; + if (conn->current_msg != NULL && conn->state == NETCONN_WRITE) { + /* Normal cleanup: current_msg is still valid, so we need to clean up + * Double-check to ensure err_tcp hasn't cleared it between check and use */ + struct api_msg *msg_to_cleanup = conn->current_msg; + if (conn->current_msg == msg_to_cleanup && conn->state == NETCONN_WRITE) { + sys_sem_t *op_completed_sem = LWIP_API_MSG_SEM(msg_to_cleanup); + msg_to_cleanup->err = err; + /* Reset state BEFORE clearing current_msg to avoid race condition: + * If poll_tcp/sent_tcp is called between these two assignments, + * we want state to be NETCONN_NONE (not NETCONN_WRITE) when current_msg is NULL */ + conn->state = NETCONN_NONE; + conn->current_msg = NULL; #if LWIP_TCPIP_CORE_LOCKING - if (delayed) + if (delayed) #endif - { - sys_sem_signal(op_completed_sem); + { + sys_sem_signal(op_completed_sem); + } + } else { + /* current_msg was changed or state changed by err_tcp between checks, skip cleanup */ } } else { /* current_msg was already cleared by err_tcp. -- 2.17.1