Skip to content

Commit

Permalink
fix: enhance clear_main_control function with sanity checks and resou…
Browse files Browse the repository at this point in the history
…rce cleanup

Signed-off-by: Dengfeng Liu <liudf0716@gmail.com>
  • Loading branch information
liudf0716 committed Nov 13, 2024
1 parent 00167fb commit ab7efe2
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions control.c
Original file line number Diff line number Diff line change
Expand Up @@ -898,16 +898,37 @@ free_main_control()
static void
clear_main_control()
{
assert(main_ctl);
if (main_ctl->ticker_ping) evtimer_del(main_ctl->ticker_ping);
if (main_ctl->tcp_mux_ping_event) evtimer_del(main_ctl->tcp_mux_ping_event);
// Sanity check
if (!main_ctl) {
debug(LOG_ERR, "main_ctl is NULL");
return;
}

// Clear timers
if (main_ctl->ticker_ping) {
evtimer_del(main_ctl->ticker_ping);
main_ctl->ticker_ping = NULL;
}

if (main_ctl->tcp_mux_ping_event) {
evtimer_del(main_ctl->tcp_mux_ping_event);
main_ctl->tcp_mux_ping_event = NULL;
}

// Clean up proxy clients and crypto context
clear_all_proxy_client();
free_evp_cipher_ctx();

// Reset state variables
set_client_status(0);
pong_time = 0;
pong_time = 0;
is_login = 0;
if (get_common_config()->tcp_mux)

// Reinitialize multiplexer stream if TCP multiplexing is enabled
struct common_conf *conf = get_common_config();
if (conf && conf->tcp_mux) {
init_tmux_stream(&main_ctl->stream, get_next_session_id(), INIT);
}
}

void close_main_control()
Expand Down

0 comments on commit ab7efe2

Please sign in to comment.