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

acassis 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 71955df3fc8 sched/task: Free the parent's copy of a fork() child's 
task_info.
71955df3fc8 is described below

commit 71955df3fc88f802239f811bac9e228017186c8d
Author: Marco Casaroli <[email protected]>
AuthorDate: Tue Oct 20 11:10:17 2026 +0200

    sched/task: Free the parent's copy of a fork() child's task_info.
    
    nxtask_setup_fork() calls group_allocate() before it copies the address
    environment of the parent.  With CONFIG_MM_KERNEL_HEAP, group_allocate()
    puts the task_info of the new group in the current user heap, that is
    the heap of the parent.  The copy gives the child the same block at the
    same address, but the parent never freed its own block: each fork()
    lost about 1 KiB of the parent's heap (1120 bytes on qemu-armv8a:knsh).
    
    Free the parent's block in nxtask_start_fork(), after the parent's
    address environment is back.  An error before this point still frees
    it through nxsched_release_tcb(), as before.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 sched/task/task_fork.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/sched/task/task_fork.c b/sched/task/task_fork.c
index 8ac24a37573..022cc07c534 100644
--- a/sched/task/task_fork.c
+++ b/sched/task/task_fork.c
@@ -503,6 +503,14 @@ pid_t nxtask_start_fork(FAR struct tcb_s *child, bool 
vfork)
       (child->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_KERNEL)
     {
       fork_restore_parent_env();
+
+#ifdef CONFIG_MM_KERNEL_HEAP
+      /* group_allocate() put the child's task_info in the parent's heap
+       * before the copy.  The child uses its own copy: free this one.
+       */
+
+      group_free(child->group, child->group->tg_info);
+#endif
     }
 #endif
 

Reply via email to