Skip to content

Commit d78aec6

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

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

control.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -898,36 +898,42 @@ free_main_control()
898898
static void
899899
clear_main_control()
900900
{
901-
// Sanity check
901+
// Validate main control exists
902902
if (!main_ctl) {
903-
debug(LOG_ERR, "main_ctl is NULL");
903+
debug(LOG_ERR, "Cannot clear NULL main control");
904904
return;
905905
}
906906

907-
// Clear timers
907+
// Clear event timers
908908
if (main_ctl->ticker_ping) {
909-
evtimer_del(main_ctl->ticker_ping);
909+
if (evtimer_del(main_ctl->ticker_ping) < 0) {
910+
debug(LOG_ERR, "Failed to delete ticker ping timer");
911+
}
910912
main_ctl->ticker_ping = NULL;
911913
}
912914

913915
if (main_ctl->tcp_mux_ping_event) {
914-
evtimer_del(main_ctl->tcp_mux_ping_event);
916+
if (evtimer_del(main_ctl->tcp_mux_ping_event) < 0) {
917+
debug(LOG_ERR, "Failed to delete TCP mux ping timer");
918+
}
915919
main_ctl->tcp_mux_ping_event = NULL;
916920
}
917921

918-
// Clean up proxy clients and crypto context
919-
clear_all_proxy_client();
920-
free_evp_cipher_ctx();
921-
922-
// Reset state variables
922+
// Reset connection state
923923
set_client_status(0);
924-
pong_time = 0;
925924
is_login = 0;
925+
pong_time = 0;
926+
927+
// Clean up resources
928+
clear_all_proxy_client();
929+
free_evp_cipher_ctx();
926930

927-
// Reinitialize multiplexer stream if TCP multiplexing is enabled
931+
// Reinitialize TCP multiplexing if enabled
928932
struct common_conf *conf = get_common_config();
929933
if (conf && conf->tcp_mux) {
930-
init_tmux_stream(&main_ctl->stream, get_next_session_id(), INIT);
934+
uint32_t session_id = get_next_session_id();
935+
init_tmux_stream(&main_ctl->stream, session_id, INIT);
936+
debug(LOG_DEBUG, "Reinitialized TCP mux stream with session ID %u", session_id);
931937
}
932938
}
933939

0 commit comments

Comments
 (0)