Skip to content

Commit

Permalink
[bt] fix if allocation fails
Browse files Browse the repository at this point in the history
If osi_malloc fails for work_queues or osi_work_queue_create fails, osi_work_queue_delete in _err may release unallocated memory.
  • Loading branch information
tgotic authored and BetterJincheng committed Oct 21, 2022
1 parent 903cb5e commit 11b6c25
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions components/bt/common/osi/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,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 = (struct work_queue **)osi_malloc(sizeof(struct work_queue *) * work_queue_num);
thread->work_queues = (struct work_queue **)osi_calloc(sizeof(struct work_queue *) * 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++) {
size_t queue_len = work_queue_len[i] ? work_queue_len[i] : DEFAULT_WORK_QUEUE_CAPACITY;
Expand Down

0 comments on commit 11b6c25

Please sign in to comment.