Skip to content

Commit 7171771

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 bde4e35 commit 7171771

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
@@ -721,12 +721,17 @@ int32_t mo_task_cancel(uint16_t id)
721721
}
722722
}
723723

724+
/* Remove from ready queue */
725+
if (tcb->state == TASK_READY) {
726+
list_node_t *rq_node = sched_dequeue_task(tcb);
727+
free(rq_node);
728+
}
729+
724730
CRITICAL_LEAVE();
725731

726732
/* Free memory outside critical section */
727733
free(tcb->stack);
728734
free(tcb);
729-
free(node);
730735
return ERR_OK;
731736
}
732737

0 commit comments

Comments
 (0)