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 49e9b62f062bcd0214d2565bf1e916acfcab8453
Author: yangjianqing <[email protected]>
AuthorDate: Wed May 13 19:23:54 2026 +0800

    net/udp: free callback in cleanup when pthread is canceled
    
    When a pthread is canceled during udp_recvfrom(), the cleanup handler
    udp_callback_cleanup() is invoked. Previously it only destroyed the
    semaphore but did not free the devif callback. This left a dangling
    callback registered on the connection, so subsequent incoming UDP
    packets would dispatch into udp_eventhandler() and call nxsem_post()
    on the already-destroyed semaphore, resulting in a use-after-free.
    
    Fix this by calling udp_callback_free() before nxsem_destroy() in the
    cleanup path, consistent with what tcp_callback_cleanup() already does
    for TCP connections.
    
    Signed-off-by: yangjianqing <[email protected]>
---
 net/udp/udp_callback.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/udp/udp_callback.c b/net/udp/udp_callback.c
index 3536a98b20b..a5c9eaee218 100644
--- a/net/udp/udp_callback.c
+++ b/net/udp/udp_callback.c
@@ -327,6 +327,7 @@ void udp_callback_cleanup(FAR void *arg)
   nerr("ERROR: pthread is being canceled, need to cleanup cb\n");
 
   conn_dev_lock(&cb->conn->sconn, cb->dev);
+  udp_callback_free(cb->dev, cb->conn, cb->udp_cb);
   if (cb->sem)
     {
       nxsem_destroy(cb->sem);

Reply via email to