Gary-Hobson commented on code in PR #13129:
URL: https://github.com/apache/nuttx/pull/13129#discussion_r1736362033
##########
sched/task/task_setup.c:
##########
@@ -170,6 +170,16 @@ static int nxtask_assign_pid(FAR struct tcb_s *tcb)
for (i = 0; i < g_npidhash / 2; i++)
{
+ if (g_pidhash[i] == NULL)
+ {
+ /* If the pid is not used, skip it.
+ * This may be triggered when a context switch occurs
+ * during mm_malloc and a thread is destroyed.
+ */
Review Comment:
Thread switching may occur during malloc, there are two situations that need
to be handled:
1. When switching, a new thread is created and g_pidhash is also expanded.
When returning, g_pidhash has changed and there may be empty elements in it. At
this time, accessing g_pidhash will access an illegal pointer

3. When switching, a thread exits, a member of g_pidhash is cleared, which
can also lead to illegal pointer access in subsequent iterations.

Since thread switching can only occur during the malloc/free process, the
other parts are protected by the critical section and thread switching will not
occur.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]