From e2235a695eb8a93f5778d50a31f8170624111080 Mon Sep 17 00:00:00 2001 From: Jeff Tenney Date: Tue, 6 Apr 2021 14:28:33 -0700 Subject: [PATCH] Send tmrCOMMAND_START_DONT_TRACE to front When reloading an auto-reload timer, the timer task sends the tmrCOMMAND_START_DONT_TRACE command if the new timer period has already elapsed. If the command queue already contains a stop or delete command for the timer, then prior to this commit the tmrCOMMAND_START_DONT_TRACE command is processed *after* the stop or delete command. Consequently the timer is restarted unexpectedly (in the stop case) or uses freed memory (in the delete case). After this commit, the tmrCOMMAND_START_DONT_TRACE command is processed before the stop or delete command. --- timers.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/timers.c b/timers.c index 203a07778..07f3b3b3f 100644 --- a/timers.c +++ b/timers.c @@ -395,7 +395,18 @@ { if( xTaskGetSchedulerState() == taskSCHEDULER_RUNNING ) { - xReturn = xQueueSendToBack( xTimerQueue, &xMessage, xTicksToWait ); + /* The "start don't trace" command comes only from the timer + * task itself. This command must be executed before any other + * commands now in the queue for this timer, in case one of + * those commands is stop or delete. */ + if( xCommandID == tmrCOMMAND_START_DONT_TRACE ) + { + xReturn = xQueueSendToFront( xTimerQueue, &xMessage, xTicksToWait ); + } + else + { + xReturn = xQueueSendToBack( xTimerQueue, &xMessage, xTicksToWait ); + } } else {