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 1046aec715f sched/group: Close the files of a group before its task 
information goes.
1046aec715f is described below

commit 1046aec715f251a10f799d6049eaed4444a09774
Author: Marco Casaroli <[email protected]>
AuthorDate: Wed Oct 21 10:56:26 2026 +0200

    sched/group: Close the files of a group before its task information goes.
    
    group_release() freed the task information (environment, streams) before
    it closed the files of the group.  With CONFIG_FS_NOTIFY, the close of a
    file queues a notification with the path of the file, and a path that is
    not absolute (a pipe) needs the current directory: lib_realpath() calls
    getcwd(), which reads PWD from the environment of the group under the
    lock of the task information.  At process exit that memory was free
    already: a process that ended with an open pipe could wait forever on a
    lock in freed memory, and its memory was not released.
    
    Close the files first, then release the task information.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 sched/group/group_leave.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/sched/group/group_leave.c b/sched/group/group_leave.c
index 404a33c82f1..9e6dc112301 100644
--- a/sched/group/group_leave.c
+++ b/sched/group/group_leave.c
@@ -105,8 +105,6 @@ static inline void group_release(FAR struct task_group_s 
*group)
 #  endif
 #endif
 
-  task_uninit_info(group);
-
 #if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS)
   /* Free all un-reaped child exit status */
 
@@ -133,6 +131,14 @@ static inline void group_release(FAR struct task_group_s 
*group)
 
   fdlist_free(&group->tg_fdlist);
 
+  /* Then the task information (environment, streams).  A file that closes
+   * above can still use it: with CONFIG_FS_NOTIFY, the close queues a
+   * notification with the path of the file, and a relative path needs the
+   * current directory from the environment (getcwd()).
+   */
+
+  task_uninit_info(group);
+
 #ifdef CONFIG_FS_CHROOT
   /* Drop the chroot jail path */
 

Reply via email to