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

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

commit 4a76be89609db54a0b8c248fc417b7f6d89ed40f
Author: Bowen Wang <[email protected]>
AuthorDate: Thu Nov 5 11:06:20 2026 +0800

    drivers/rptun: fix the double free when autostart fails
    
    When rptun_dev_start() fails in rptun_initialize(), unregister_driver()
    unlinks the node, so rptun_dev_unlink() frees priv, and
    rptun_initialize() then frees it again. The unlink also does dq_rem()
    on a priv that was never queued, which empties g_rptun_priv.
    
    Free priv in rptun_initialize() only when there is no unlink, and let
    the unlink skip dq_rem() for a priv that is not queued.
    
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/rptun/rptun.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/rptun/rptun.c b/drivers/rptun/rptun.c
index ccedaba0211..bc8a3f0958e 100644
--- a/drivers/rptun/rptun.c
+++ b/drivers/rptun/rptun.c
@@ -1394,8 +1394,14 @@ static int rptun_dev_unlink(FAR struct inode *inode)
       return ret;
     }
 
+  /* Not queued when unlinked by a failed rptun_initialize() */
+
   nxrmutex_lock(&g_rptun_lock);
-  dq_rem(&priv->entry, &g_rptun_priv);
+  if (dq_inqueue(&priv->entry, &g_rptun_priv))
+    {
+      dq_rem(&priv->entry, &g_rptun_priv);
+    }
+
   nxrmutex_unlock(&g_rptun_lock);
 
   remoteproc_remove(&priv->rproc);
@@ -1702,7 +1708,9 @@ int rptun_initialize(FAR struct rptun_dev_s *dev)
               if (ret < 0)
                 {
                   unregister_driver(name);
+#ifdef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
                   kmm_free(priv);
+#endif
                   rptunerr("rptun start failed %d\n", ret);
                 }
             }

Reply via email to