From 91dfbd01e8c847deb23d925c732c98a413b51606 Mon Sep 17 00:00:00 2001 From: Peter Harper <77111776+peterharperuk@users.noreply.github.com> Date: Thu, 17 Oct 2024 19:55:20 +0100 Subject: [PATCH] Fix issue with free rtos execute sync (#1979) Stop handle_sync_func_call removing the worker. Depending on thread priority this can occur after the memory has gone out of scope in async_context_freertos_execute_sync. Fixes #1962 --- src/rp2_common/pico_async_context/async_context_freertos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/pico_async_context/async_context_freertos.c b/src/rp2_common/pico_async_context/async_context_freertos.c index a4304d47..3cffcbb9 100644 --- a/src/rp2_common/pico_async_context/async_context_freertos.c +++ b/src/rp2_common/pico_async_context/async_context_freertos.c @@ -188,7 +188,6 @@ static void handle_sync_func_call(async_context_t *context, async_when_pending_w sync_func_call_t *call = (sync_func_call_t *)worker; call->rc = call->func(call->param); xSemaphoreGive(call->sem); - async_context_remove_when_pending_worker(context, worker); } uint32_t async_context_freertos_execute_sync(async_context_t *self_base, uint32_t (*func)(void *param), void *param) { @@ -202,6 +201,7 @@ uint32_t async_context_freertos_execute_sync(async_context_t *self_base, uint32_ async_context_add_when_pending_worker(self_base, &call.worker); async_context_set_work_pending(self_base, &call.worker); xSemaphoreTake(call.sem, portMAX_DELAY); + async_context_remove_when_pending_worker(self_base, &call.worker); vSemaphoreDelete(call.sem); return call.rc; }