From 2a77b9fcc74ba8715e7c725d1d880883b36c813f Mon Sep 17 00:00:00 2001 From: goldsimon Date: Tue, 3 Jul 2007 20:20:33 +0000 Subject: [PATCH] Bug in last version (fix to close problems): netconn thread might get active before calling its callback, so conn was already deallocated. --- src/api/api_msg.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/api/api_msg.c b/src/api/api_msg.c index 0ef1db2e..2f866448 100644 --- a/src/api/api_msg.c +++ b/src/api/api_msg.c @@ -464,6 +464,13 @@ do_close_internal(struct netconn *conn) conn->state = NETCONN_NONE; conn->pcb.tcp = NULL; conn->err = err; + /* Trigger select() in socket layer */ + if (conn->callback) { + /* this should send something else so the errorfd is set, + not the read and write fd! */ + (*conn->callback)(conn, NETCONN_EVT_RCVPLUS, 0); + (*conn->callback)(conn, NETCONN_EVT_SENDPLUS, 0); + } /* wake up the application task */ sys_mbox_post(conn->mbox, NULL); break; @@ -503,26 +510,26 @@ do_delconn(struct api_msg_msg *msg) case NETCONN_TCP: msg->conn->state = NETCONN_CLOSE; do_close_internal(msg->conn); + /* conn->callback is called inside do_close_internal, before releasing + the application thread, so we can return at this point! */ + return; break; #endif /* LWIP_TCP */ default: break; } } + /* tcp netconns don't come here! */ + /* Trigger select() in socket layer */ if (msg->conn->callback) { + /* this send should something else so the errorfd is set, + not the read and write fd! */ (*msg->conn->callback)(msg->conn, NETCONN_EVT_RCVPLUS, 0); (*msg->conn->callback)(msg->conn, NETCONN_EVT_SENDPLUS, 0); } - if ((msg->conn->mbox != SYS_MBOX_NULL) -#if LWIP_TCP - /* for tcp netconns, do_close_internal ACKs the message */ - && (NETCONNTYPE_GROUP(msg->conn->type) != NETCONN_TCP)) -#else - ) -#endif - { + if (msg->conn->mbox != SYS_MBOX_NULL) { TCPIP_APIMSG_ACK(msg); } }