From 13d54794497ee7b381038cdd9bf8456ee939bd40 Mon Sep 17 00:00:00 2001 From: Maarten Zanders Date: Mon, 9 Mar 2026 13:24:39 +0100 Subject: [PATCH] sched/group: prevent mm_free() of static g_kthread_group When building for small systems with CONFIG_DEFAULT_SMALL=y, this implies CONFIG_DISABLE_PTHREAD and thus HAVE_GROUP_MEMBERS is undefined. When the AppBringUp task finishes, it will in this case try to free g_kthread_group which is obviously not possible. Add a guard with a new flag "GROUP_FLAG_STATIC" which indicates the memory allocation type. Before freeing, check for this flag. Signed-off-by: Maarten Zanders --- include/nuttx/sched.h | 3 ++- sched/group/group_create.c | 1 + sched/group/group_leave.c | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index 05f792a92d190..33dc10bebd482 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -117,7 +117,8 @@ #define GROUP_FLAG_PRIVILEGED (1 << 1) /* Bit 1: Group is privileged */ #define GROUP_FLAG_DELETED (1 << 2) /* Bit 2: Group has been deleted but not yet freed */ #define GROUP_FLAG_EXITING (1 << 3) /* Bit 3: Group exit is in progress */ - /* Bits 3-7: Available */ +#define GROUP_FLAG_STATIC (1 << 4) /* Bit 4: Group is statically allocated */ + /* Bits 5-7: Available */ /* Values for struct child_status_s ch_flags */ diff --git a/sched/group/group_create.c b/sched/group/group_create.c index 122a25d06d666..bda2ccd738428 100644 --- a/sched/group/group_create.c +++ b/sched/group/group_create.c @@ -131,6 +131,7 @@ int group_allocate(FAR struct tcb_s *tcb, uint8_t ttype) { group = &g_kthread_group; tcb->group = group; + group->tg_flags |= GROUP_FLAG_STATIC; if (group->tg_info) { return OK; diff --git a/sched/group/group_leave.c b/sched/group/group_leave.c index 4ba91b1af97cc..1998629753acf 100644 --- a/sched/group/group_leave.c +++ b/sched/group/group_leave.c @@ -238,7 +238,8 @@ void group_drop(FAR struct task_group_s *group) /* Finally, if no one needs the group and it has been deleted, remove it */ - if (group->tg_flags & GROUP_FLAG_DELETED) + if ((group->tg_flags & GROUP_FLAG_DELETED) && + !(group->tg_flags & GROUP_FLAG_STATIC)) { /* Release the group container itself */