sched/environ: check envcp validity before hold sched_lock()

check envcp validity before hold sched_lock() to avoid unnecessary schedule lock

Signed-off-by: chao an <anchao@lixiang.com>
This commit is contained in:
chao an 2024-03-05 10:39:27 +08:00 committed by Xiang Xiao
parent 73c4f2f1e7
commit dfd1e38b40

View file

@ -70,16 +70,16 @@ int env_dup(FAR struct task_group_s *group, FAR char * const *envcp)
DEBUGASSERT(group != NULL);
/* Pre-emption must be disabled throughout the following because the
* environment may be shared.
*/
sched_lock();
/* Is there an environment ? */
if (envcp != NULL)
{
/* Pre-emption must be disabled throughout the following because the
* environment may be shared.
*/
sched_lock();
/* Count the strings */
while (envcp[envc] != NULL)
@ -138,9 +138,10 @@ int env_dup(FAR struct task_group_s *group, FAR char * const *envcp)
/* Save the child environment allocation. */
group->tg_envp = envp;
sched_unlock();
}
sched_unlock();
return ret;
}