Skip to content

Commit ab7efe2

Browse files
committed
fix: enhance clear_main_control function with sanity checks and resource cleanup
Signed-off-by: Dengfeng Liu <[email protected]>
1 parent 00167fb commit ab7efe2

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

control.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -898,16 +898,37 @@ free_main_control()
898898
static void
899899
clear_main_control()
900900
{
901-
assert(main_ctl);
902-
if (main_ctl->ticker_ping) evtimer_del(main_ctl->ticker_ping);
903-
if (main_ctl->tcp_mux_ping_event) evtimer_del(main_ctl->tcp_mux_ping_event);
901+
// Sanity check
902+
if (!main_ctl) {
903+
debug(LOG_ERR, "main_ctl is NULL");
904+
return;
905+
}
906+
907+
// Clear timers
908+
if (main_ctl->ticker_ping) {
909+
evtimer_del(main_ctl->ticker_ping);
910+
main_ctl->ticker_ping = NULL;
911+
}
912+
913+
if (main_ctl->tcp_mux_ping_event) {
914+
evtimer_del(main_ctl->tcp_mux_ping_event);
915+
main_ctl->tcp_mux_ping_event = NULL;
916+
}
917+
918+
// Clean up proxy clients and crypto context
904919
clear_all_proxy_client();
905920
free_evp_cipher_ctx();
921+
922+
// Reset state variables
906923
set_client_status(0);
907-
pong_time = 0;
924+
pong_time = 0;
908925
is_login = 0;
909-
if (get_common_config()->tcp_mux)
926+
927+
// Reinitialize multiplexer stream if TCP multiplexing is enabled
928+
struct common_conf *conf = get_common_config();
929+
if (conf && conf->tcp_mux) {
910930
init_tmux_stream(&main_ctl->stream, get_next_session_id(), INIT);
931+
}
911932
}
912933

913934
void close_main_control()

0 commit comments

Comments
 (0)