From 7cd8fd0689fed6ef04e1ef4f182147aea9e6b2c8 Mon Sep 17 00:00:00 2001 From: Zhang Hai Peng Date: Tue, 30 Dec 2025 11:53:52 +0800 Subject: [PATCH] fix(bt/osi): add NULL check in osi_mutex_free and osi_sem_free (IDFGH-16853) (cherry picked from commit 863004060215b4730aafa15914729175a2f0f173) Co-authored-by: zhanghaipeng --- components/bt/common/osi/mutex.c | 9 +++++++-- components/bt/common/osi/semaphore.c | 8 +++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/components/bt/common/osi/mutex.c b/components/bt/common/osi/mutex.c index b7fe38a1ee..5a4de81ee5 100644 --- a/components/bt/common/osi/mutex.c +++ b/components/bt/common/osi/mutex.c @@ -65,10 +65,15 @@ void osi_mutex_unlock(osi_mutex_t *mutex) xSemaphoreGive(*mutex); } -/** Delete a semaphore - * @param mutex the mutex to delete */ +/** Delete a mutex + * @param mutex the mutex to delete + * Note: Safe to call with NULL or uninitialized mutex (IDFGH-16853) + */ void osi_mutex_free(osi_mutex_t *mutex) { + if (mutex == NULL || *mutex == NULL) { + return; + } vSemaphoreDelete(*mutex); *mutex = NULL; } diff --git a/components/bt/common/osi/semaphore.c b/components/bt/common/osi/semaphore.c index 14823160e3..5acbb67b8f 100644 --- a/components/bt/common/osi/semaphore.c +++ b/components/bt/common/osi/semaphore.c @@ -69,9 +69,15 @@ osi_sem_take(osi_sem_t *sem, uint32_t timeout) return ret; } -// Deallocates a semaphore +/** Deallocates a semaphore + * @param sem the semaphore to delete + * Note: Safe to call with NULL or uninitialized semaphore (IDFGH-16853) + */ void osi_sem_free(osi_sem_t *sem) { + if (sem == NULL || *sem == NULL) { + return; + } vSemaphoreDelete(*sem); *sem = NULL; }