Skip to content

Commit

Permalink
fix: improve error handling and resource cleanup in close_main_contro…
Browse files Browse the repository at this point in the history
…l function

Signed-off-by: Dengfeng Liu <[email protected]>
  • Loading branch information
liudf0716 committed Nov 13, 2024
1 parent ae8a0c7 commit 00167fb
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions control.c
Original file line number Diff line number Diff line change
Expand Up @@ -910,15 +910,32 @@ clear_main_control()
init_tmux_stream(&main_ctl->stream, get_next_session_id(), INIT);
}

void
close_main_control()
void close_main_control()
{
if (!main_ctl) {
debug(LOG_ERR, "main_ctl is NULL");
return;
}

// Clean up resources and state
clear_main_control();

event_base_dispatch(main_ctl->connect_base);
evdns_base_free(main_ctl->dnsbase, 0);
event_base_free(main_ctl->connect_base);
// Free event bases
if (main_ctl->connect_base) {
if (event_base_dispatch(main_ctl->connect_base) < 0) {
debug(LOG_ERR, "event_base_dispatch failed");
}

if (main_ctl->dnsbase) {
evdns_base_free(main_ctl->dnsbase, 0);
main_ctl->dnsbase = NULL;
}

event_base_free(main_ctl->connect_base);
main_ctl->connect_base = NULL;
}

// Free the main control structure
free_main_control();
}

Expand Down

0 comments on commit 00167fb

Please sign in to comment.