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


The following commit(s) were added to refs/heads/master by this push:
     new 59cb24ea20c binfmt/exec_module: fix double free of the TCB on late 
failures
59cb24ea20c is described below

commit 59cb24ea20cd522f4e549274983e8b93bb778781
Author: huojianchao <[email protected]>
AuthorDate: Mon Nov 3 22:23:57 2025 +0800

    binfmt/exec_module: fix double free of the TCB on late failures
    
    exec_module() sets TCB_FLAG_FREE_TCB before nxtask_init(), so on the
    errout_with_tcbinit path nxtask_uninit() already frees the TCB through
    nxsched_release_tcb().  The error path then falls through to
    errout_with_tcb and calls kmm_free() on it a second time.
    
    This path is taken when addrenv_attach(), addrenv_restore() or
    spawn_execattrs() fails, e.g. for posix_spawn() of a file with
    POSIX_SPAWN_SETSCHEDULER and a scheduling policy that is not configured.
    
    Clear tcb after nxtask_uninit() so that the final kmm_free() does
    nothing.
    
    Signed-off-by: huojianchao <[email protected]>
---
 binfmt/binfmt_execmodule.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/binfmt/binfmt_execmodule.c b/binfmt/binfmt_execmodule.c
index 6704572ddd4..b9f48bcee67 100644
--- a/binfmt/binfmt_execmodule.c
+++ b/binfmt/binfmt_execmodule.c
@@ -444,6 +444,7 @@ errout_with_tcbinit:
 #endif
 
   nxtask_uninit(tcb);
+  tcb = NULL;
 
 errout_with_addrenv:
 #if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)

Reply via email to