Преглед изворни кода

Merge branch 'bugfix/handle_issue_of_malloc_fail' into 'master'

bugfix/avoid unexpected free when malloc failed

Closes IDFGH-8518

See merge request espressif/esp-idf!20723
Wang Meng Yang пре 3 година
родитељ
комит
2d2d0ba1f3
1 измењених фајлова са 3 додато и 3 уклоњено
  1. 3 3
      components/bt/common/osi/thread.c

+ 3 - 3
components/bt/common/osi/thread.c

@@ -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;