Просмотр исходного кода

[HUST CSE] avoids the risk of a null pointer (#191)

codlearner 2 лет назад
Родитель
Сommit
dc05133d47
1 измененных файлов с 9 добавлено и 7 удалено
  1. 9 7
      port/mpthreadport.c

+ 9 - 7
port/mpthreadport.c

@@ -130,13 +130,15 @@ void mp_thread_create_ex(void *(*entry)(void*), void *arg, size_t *stack_size, i
     if (th == NULL) {
         nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "can't create thread obj"));
     }
-    th->id = m_new_obj(struct rt_thread);
-    if (th->id == NULL) {
-        nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "can't create thread id"));
-    }
-    th->stack = m_new(uint8_t, *stack_size);
-    if (th->stack == NULL) {
-        nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "can't create thread stack"));
+    else {
+        th->id = m_new_obj(struct rt_thread);
+        if (th->id == NULL) {
+            nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "can't create thread id"));
+        }
+        th->stack = m_new(uint8_t, *stack_size);
+        if (th->stack == NULL) {
+            nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "can't create thread stack"));
+        }
     }
 
     mp_thread_mutex_lock(&thread_mutex, 1);