frameworks_bluetooth/tools/async
v-chenghuijin 57ebf5d7f9 SPP: Fix race condition crash by unifying thread context for resource cleanup
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>
2026-01-23 09:22:13 +08:00
..
adv.c ipc: le advertiser async api 2025-08-08 13:52:12 +08:00
gap.c SPP: Fix race condition crash by unifying thread context for resource cleanup 2026-01-23 09:22:13 +08:00
gatt_client.c bluetooth: Fix the memory leak issue in gattc. 2025-10-22 19:15:36 +08:00
log.c ipc: trace async api 2025-10-15 10:20:50 +08:00
scan.c ipc: le scan async api 2025-10-15 10:20:50 +08:00