Commit 1c2d0bd
committed
dialog: atomic state transition to close BYE/timer races (GH-3835)
The previous fix (196b51f) narrowed the race window between BYE
processing and dlg_ontimeout() but could not fully close it: a BYE
arriving between the state check and dlg_end_dlg() creates a TM
transaction ref (via dlg_set_tm_dialog_ctx) that outlives the dialog.
When the timeout-BYE responses destroy the dialog first, the real
BYE's transaction callback dereferences freed memory.
The same race pattern exists in dlg_options_routine() and
dlg_reinvite_routine(), where expired ping dialogs call dlg_end_dlg()
without any state transition.
Fix: replace racy state checks with atomic next_state_dlg(DLG_EVENT_REQBYE)
calls. The hash entry lock guarantees only one code path -- timer,
ping handler, or BYE handler -- wins the CONFIRMED -> DELETED transition.
Since dual_bye_event() now only sees DELETED -> DELETED for the
timeout-BYE responses, the cleanup that it would normally perform on
the first CONFIRMED -> DELETED transition (rt_on_hangup, profile
linkers, DLGCB_TERMINATED callback, DB removal) is moved into the
winning timeout/ping path.
Three paths fixed:
- dlg_ontimeout() bye_on_timeout (dlg_handlers.c)
- dlg_options_routine() expired pings (dlg_timer.c)
- dlg_reinvite_routine() expired pings (dlg_timer.c)
Ref: #38351 parent 8f959e7 commit 1c2d0bd
2 files changed
+124
-26
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2670 | 2670 | | |
2671 | 2671 | | |
2672 | 2672 | | |
2673 | | - | |
2674 | | - | |
2675 | | - | |
2676 | | - | |
2677 | | - | |
2678 | | - | |
2679 | | - | |
| 2673 | + | |
| 2674 | + | |
| 2675 | + | |
| 2676 | + | |
| 2677 | + | |
| 2678 | + | |
| 2679 | + | |
| 2680 | + | |
| 2681 | + | |
| 2682 | + | |
| 2683 | + | |
| 2684 | + | |
| 2685 | + | |
| 2686 | + | |
| 2687 | + | |
| 2688 | + | |
| 2689 | + | |
| 2690 | + | |
| 2691 | + | |
| 2692 | + | |
| 2693 | + | |
| 2694 | + | |
| 2695 | + | |
| 2696 | + | |
| 2697 | + | |
| 2698 | + | |
| 2699 | + | |
| 2700 | + | |
| 2701 | + | |
| 2702 | + | |
| 2703 | + | |
| 2704 | + | |
| 2705 | + | |
| 2706 | + | |
| 2707 | + | |
| 2708 | + | |
| 2709 | + | |
| 2710 | + | |
| 2711 | + | |
| 2712 | + | |
| 2713 | + | |
| 2714 | + | |
| 2715 | + | |
| 2716 | + | |
| 2717 | + | |
| 2718 | + | |
| 2719 | + | |
| 2720 | + | |
| 2721 | + | |
| 2722 | + | |
| 2723 | + | |
| 2724 | + | |
| 2725 | + | |
| 2726 | + | |
| 2727 | + | |
| 2728 | + | |
| 2729 | + | |
| 2730 | + | |
| 2731 | + | |
| 2732 | + | |
2680 | 2733 | | |
2681 | | - | |
2682 | | - | |
2683 | | - | |
2684 | | - | |
2685 | | - | |
2686 | | - | |
2687 | | - | |
2688 | 2734 | | |
| 2735 | + | |
| 2736 | + | |
| 2737 | + | |
2689 | 2738 | | |
2690 | 2739 | | |
2691 | 2740 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
29 | 33 | | |
30 | 34 | | |
31 | 35 | | |
| |||
888 | 892 | | |
889 | 893 | | |
890 | 894 | | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
891 | 946 | | |
892 | 947 | | |
893 | 948 | | |
| |||
915 | 970 | | |
916 | 971 | | |
917 | 972 | | |
918 | | - | |
919 | | - | |
920 | | - | |
921 | | - | |
922 | | - | |
923 | | - | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
924 | 976 | | |
925 | 977 | | |
926 | 978 | | |
| |||
1022 | 1074 | | |
1023 | 1075 | | |
1024 | 1076 | | |
1025 | | - | |
1026 | | - | |
1027 | | - | |
1028 | | - | |
1029 | | - | |
1030 | | - | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
1031 | 1080 | | |
1032 | 1081 | | |
1033 | 1082 | | |
| |||
0 commit comments