bug: v/80850 Rootcause: uv_loop_close() marks internal data structures as invalid, but pending callbacks in the queue still reference these invalidated structures. When uv_run() is called later, it processes the queue using corrupted pointers, leading to segmentation faults and crashes. Solution:To address the issues described above, the solution removes uv_loop_t from the bttool_t struct and changes it to dynamic allocation, introducing a global pointer g_bttool_loop to centrally manage its lifecycle. Specific modifications include: dynamically allocating and initializing the uv_loop_t instance within the bttool_thread function and assigning it to the global pointer; modifying the bttool_command_uvloop_run function to operate using the global g_bttool_loop pointer; and adjusting the asynchronous API initialization logic in async/gap.c to ensure it uses the global pointer instead of a local pointer. Furthermore, the solution enhances error handling, ensuring proper resource cleanup if memory allocation fails, and optimizes the bt_tool_uninit_cb function to prevent premature clearing of the global pointer, which could lead to access exceptions. Signed-off-by: v-chenghuijin <v-chenghuijin@xiaomi.com> |
||
|---|---|---|
| .. | ||
| adv.c | ||
| gap.c | ||
| gatt_client.c | ||
| log.c | ||
| scan.c | ||