Skip to content

Commit 1ec0240

Browse files
committed
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 <maarten@zanders.be>
1 parent ebc75b0 commit 1ec0240

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

include/nuttx/sched.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@
117117
#define GROUP_FLAG_PRIVILEGED (1 << 1) /* Bit 1: Group is privileged */
118118
#define GROUP_FLAG_DELETED (1 << 2) /* Bit 2: Group has been deleted but not yet freed */
119119
#define GROUP_FLAG_EXITING (1 << 3) /* Bit 3: Group exit is in progress */
120-
/* Bits 3-7: Available */
120+
#define GROUP_FLAG_STATIC (1 << 4) /* Bit 4: Group is statically allocated */
121+
/* Bits 5-7: Available */
121122

122123
/* Values for struct child_status_s ch_flags */
123124

sched/group/group_create.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ int group_allocate(FAR struct tcb_s *tcb, uint8_t ttype)
131131
{
132132
group = &g_kthread_group;
133133
tcb->group = group;
134+
group->tg_flags |= GROUP_FLAG_STATIC;
134135
if (group->tg_info)
135136
{
136137
return OK;

sched/group/group_leave.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ void group_drop(FAR struct task_group_s *group)
238238

239239
/* Finally, if no one needs the group and it has been deleted, remove it */
240240

241-
if (group->tg_flags & GROUP_FLAG_DELETED)
241+
if ((group->tg_flags & GROUP_FLAG_DELETED) &&
242+
!(group->tg_flags & GROUP_FLAG_STATIC))
242243
{
243244
/* Release the group container itself */
244245

0 commit comments

Comments
 (0)