connections free free
This commit is contained in:
1 parent
481788c4f3
commit
0e36d5993c
2 files changed
+24
-5
No files matched your search
+23
-4
@@ -500,8 +500,12 @@ void etcp_socket_remove(struct ETCP_SOCKET* conn) {
|
||||
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "[ETCP] Closed socket");
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < conn->num_channels; i++) {
|
||||
etcp_link_close(conn->links[i]);
|
||||
|
||||
size_t i = 0;
|
||||
while (i < conn->num_channels) {
|
||||
struct ETCP_LINK* l = conn->links[i];
|
||||
etcp_link_close(l); // теперь безопасно — num_channels уменьшится, но i не растёт
|
||||
// i НЕ инкрементируем — сдвиг уже сделал remove_link
|
||||
}
|
||||
u_free(conn->links);
|
||||
|
||||
@@ -558,7 +562,13 @@ struct ETCP_LINK* etcp_link_new(struct ETCP_CONN* etcp, struct ETCP_SOCKET* conn
|
||||
link->ip_port_hash = sockaddr_hash(remote_addr);
|
||||
link->last_recv_local_time = get_time_tb(); // Initialize to prevent immediate timeout
|
||||
|
||||
insert_link(conn, link);
|
||||
// insert_link(conn, link);
|
||||
if (insert_link(conn, link) < 0) {
|
||||
// откатываем то, что успели
|
||||
// (пока список ещё не добавлен — просто free)
|
||||
u_free(link);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct ETCP_LINK* l=etcp->links;
|
||||
while (l && l->next) l=l->next;
|
||||
@@ -574,7 +584,15 @@ struct ETCP_LINK* etcp_link_new(struct ETCP_CONN* etcp, struct ETCP_SOCKET* conn
|
||||
|
||||
void etcp_link_close(struct ETCP_LINK* link) {
|
||||
DEBUG_TRACE(DEBUG_CATEGORY_CONNECTION, "");
|
||||
if (!link || !link->etcp) return;
|
||||
if (!link) return;
|
||||
if (!link->conn) {
|
||||
// только удаляем из списка и free
|
||||
struct ETCP_LINK **pp = &link->etcp->links;
|
||||
while (*pp && *pp != link) pp = &(*pp)->next;
|
||||
if (*pp) *pp = link->next;
|
||||
u_free(link);
|
||||
return;
|
||||
}
|
||||
|
||||
// Cancel init timer if active
|
||||
if (link->init_timer) {
|
||||
@@ -1066,6 +1084,7 @@ process_decrypted:
|
||||
// log_dump("RECV decrypted:", pkt->data, pkt->data_len, link);
|
||||
|
||||
if (link->link_state == 3) etcp_conn_input(pkt);
|
||||
else memory_pool_free(e_sock->instance->pkt_pool, pkt);
|
||||
return;
|
||||
|
||||
ec_fr:
|
||||
|
||||
+1
-1
@@ -424,6 +424,7 @@ int main(int argc, char *argv[]) {
|
||||
utun_instance_destroy(instance);
|
||||
}
|
||||
|
||||
|
||||
// Destroy uasync instance after instance is destroyed
|
||||
if (ua) {
|
||||
uasync_destroy(ua, 0);
|
||||
@@ -431,6 +432,5 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
remove_pidfile(args.pid_file);
|
||||
socket_platform_cleanup();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user