From dc4c846d329ba0d9d7bb1bb8aa13f959654ed31a Mon Sep 17 00:00:00 2001 From: yushuailong Date: Tue, 8 Sep 2026 20:16:43 +0800 Subject: [PATCH] sched/environ: Serialize clearenv updates. Protect the environment release in clearenv() with the task group mutex. This prevents concurrent environment operations from racing with cleanup. Assisted-by: OpenAI Codex Signed-off-by: yushuailong --- sched/environ/env_clearenv.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sched/environ/env_clearenv.c b/sched/environ/env_clearenv.c index baed11bd223..df04888ce1b 100644 --- a/sched/environ/env_clearenv.c +++ b/sched/environ/env_clearenv.c @@ -60,9 +60,13 @@ int clearenv(void) { FAR struct tcb_s *tcb = this_task(); - DEBUGASSERT(tcb->group); + FAR struct task_group_s *group = tcb->group; - env_release(tcb->group); + DEBUGASSERT(group); + + nxrmutex_lock(&group->tg_mutex); + env_release(group); + nxrmutex_unlock(&group->tg_mutex); return OK; }