Commit b1ecc40
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
(e.g., set to -1), 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:We modified the adapter state change callback
(on_adapter_state_changed_cb) in bt_tools.c. When the adapter state is
detected to be turning off, instead of directly calling the cleanup
function, the task bt_tool_uninit_cb is now dispatched to the bttool_loop
thread for sequential execution via do_in_thread_loop. This approach
ensures all resource cleanup operations—including the critical
spp_command_uninit call—are completed sequentially within the same thread
context, completely eliminating the possibility of concurrent access.
Signed-off-by: v-chenghuijin <v-chenghuijin@xiaomi.com>1 parent fe34376 commit b1ecc40
File tree
4 files changed
+18
-13
lines changed- framework/common
- service/common
- tools
4 files changed
+18
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
| 226 | + | |
| 227 | + | |
230 | 228 | | |
231 | 229 | | |
232 | 230 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
| 290 | + | |
| 291 | + | |
294 | 292 | | |
295 | 293 | | |
296 | 294 | | |
| |||
| 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 | + | |
1598 | 1604 | | |
1599 | 1605 | | |
1600 | 1606 | | |
| |||
1616 | 1622 | | |
1617 | 1623 | | |
1618 | 1624 | | |
1619 | | - | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
1620 | 1628 | | |
1621 | 1629 | | |
1622 | 1630 | | |
| |||
1906 | 1914 | | |
1907 | 1915 | | |
1908 | 1916 | | |
1909 | | - | |
| 1917 | + | |
1910 | 1918 | | |
1911 | 1919 | | |
1912 | 1920 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | 16 | | |
19 | | - | |
20 | 17 | | |
21 | 18 | | |
22 | 19 | | |
23 | 20 | | |
24 | 21 | | |
25 | 22 | | |
26 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
0 commit comments