From b37b8f163b17b53b1874cc9ab293205b552628ff Mon Sep 17 00:00:00 2001 From: tgotic Date: Thu, 13 Oct 2022 18:02:11 +0200 Subject: [PATCH] [bt] fix if allocation fails If osi_malloc fails for work_queues or osi_work_queue_create fails, osi_work_queue_delete in _err may release unallocated memory. --- components/bt/common/osi/thread.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/bt/common/osi/thread.c b/components/bt/common/osi/thread.c index 37e090b68e..e4840d013a 100644 --- a/components/bt/common/osi/thread.c +++ b/components/bt/common/osi/thread.c @@ -118,17 +118,17 @@ osi_thread_t *osi_thread_create(const char *name, size_t stack_size, int priorit return NULL; } - osi_thread_t *thread = (osi_thread_t *)osi_malloc(sizeof(osi_thread_t)); + osi_thread_t *thread = (osi_thread_t *)osi_calloc(sizeof(osi_thread_t)); if (thread == NULL) { goto _err; } thread->stop = false; - thread->work_queue_num = work_queue_num; - thread->work_queues = (fixed_queue_t **)osi_malloc(sizeof(fixed_queue_t *) * work_queue_num); + thread->work_queues = (fixed_queue_t **)osi_calloc(sizeof(fixed_queue_t *) * work_queue_num); if (thread->work_queues == NULL) { goto _err; } + thread->work_queue_num = work_queue_num; for (int i = 0; i < thread->work_queue_num; i++) { thread->work_queues[i] = fixed_queue_new(DEFAULT_WORK_QUEUE_CAPACITY);