Add ownership check when giving a mutex

Disallow a held mutex from being given by another task,
one that did not first take the mutex.
This commit is contained in:
cookpate 2026-07-21 15:57:20 -07:00
parent 78069a79ea
commit c028ff4bf5

14
queue.c
View file

@ -966,6 +966,20 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
} }
#endif #endif
#if ( configUSE_MUTEXES == 1 )
{
/* If the queue is a mutex and is held, only the owner can give it. */
if( ( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX ) &&
( pxQueue->u.xSemaphore.xMutexHolder != NULL ) &&
( pxQueue->u.xSemaphore.xMutexHolder != xTaskGetCurrentTaskHandle() ) )
{
traceRETURN_xQueueGenericSend( pdFAIL );
return pdFAIL;
}
}
#endif /* configUSE_MUTEXES */
for( ; ; ) for( ; ; )
{ {
taskENTER_CRITICAL(); taskENTER_CRITICAL();