Handle queue and task allocation failures before starting sensor work

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>
This commit is contained in:
Rudy Celekli
2026-10-05 11:59:06 -04:00
parent 83294689da
commit 2d1fa1c896
@@ -60,7 +60,16 @@ static void sensor_task(void *arg) {
void app_main(void) {
sensor_queue = xQueueCreate(8, sizeof(sensor_data_t));
xTaskCreate(sensor_task, "sensor", TASK_STACK_SIZE, NULL, TASK_PRIORITY, NULL);
if (sensor_queue == NULL) {
// Never start a task that will send to an invalid queue.
return; // Report allocation failure through the application's fault path.
}
if (xTaskCreate(sensor_task, "sensor", TASK_STACK_SIZE, NULL,
TASK_PRIORITY, NULL) != pdPASS) {
vQueueDelete(sensor_queue);
sensor_queue = NULL;
return; // No task owns the queue; release it before reporting the fault.
}
}
```