Skip to content

Commit b542b37

Browse files
committed
Add ready queue dequeue path in mo_task_cancel()
Previously, mo_task_cancel() only removed the task node from the global task list (kcb->tasks) but did not remove it from the ready queue. As a result, the scheduler could still select a canceled task that remained in the ready queue. Additionally, freeing the node twice could occur because the same node was already freed after list_remove(), leading to a double-free issue. This change adds a call to sched_dequeue_task() to remove the task from the ready queue, ensuring that once a task is canceled, it will no longer appear in the scheduler’s selection path. This also prevents memory corruption caused by double-freeing list nodes.
1 parent 998986e commit b542b37

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

kernel/task.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,12 +716,17 @@ int32_t mo_task_cancel(uint16_t id)
716716
}
717717
}
718718

719+
/* Remove from ready queue */
720+
if (tcb->state == TASK_READY) {
721+
list_node_t *rq_node = sched_dequeue_task(tcb);
722+
free(rq_node);
723+
}
724+
719725
CRITICAL_LEAVE();
720726

721727
/* Free memory outside critical section */
722728
free(tcb->stack);
723729
free(tcb);
724-
free(node);
725730
return ERR_OK;
726731
}
727732

0 commit comments

Comments
 (0)