Commit 647b511
committed
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:Resolve race conditions by serializing cleanup operations:
Change the cleanup operation triggered by Bluetooth adapter shutdown to
be asynchronously submitted to the bttool_loop thread for sequential
execution. Set the global pointer g_bttool_loop_ptr to directly point to
bttool->loop, avoiding data duplication. In the on_adapter_state_changed_cb
callback, use do_in_thread_loop(g_bttool_loop_ptr, bt_tool_uninit_cb, NULL)
to submit the cleanup task to the bttool_loop thread, ensuring it executes
sequentially in the same thread as the cleanup operation for user exit
commands, thereby completely eliminating race conditions.
Signed-off-by: v-chenghuijin <[email protected]>1 parent a509681 commit 647b511
1 file changed
+11
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| 90 | + | |
90 | 91 | | |
91 | 92 | | |
92 | 93 | | |
| |||
1595 | 1596 | | |
1596 | 1597 | | |
1597 | 1598 | | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
1598 | 1605 | | |
1599 | 1606 | | |
1600 | 1607 | | |
| |||
1616 | 1623 | | |
1617 | 1624 | | |
1618 | 1625 | | |
1619 | | - | |
| 1626 | + | |
| 1627 | + | |
| 1628 | + | |
1620 | 1629 | | |
1621 | 1630 | | |
1622 | 1631 | | |
| |||
1906 | 1915 | | |
1907 | 1916 | | |
1908 | 1917 | | |
1909 | | - | |
| 1918 | + | |
1910 | 1919 | | |
1911 | 1920 | | |
1912 | 1921 | | |
| |||
0 commit comments