diff --git a/src/etcp.c b/src/etcp.c index 8114fa89..7acadd93 100644 --- a/src/etcp.c +++ b/src/etcp.c @@ -302,23 +302,26 @@ void etcp_connection_close(struct ETCP_CONN* etcp) { etcp->normalizer = NULL; } - // Drain and free all queues using helper functions + // Clear links BEFORE draining queues: etcp_link_close calls + // etcp_conn_on_inflight_lim_changed -> input_queue_try_resume + // which accesses input_send_q, input_queue, input_wait_ack. + if (etcp->links) { + struct ETCP_LINK* link = etcp->links; + while (link) { + struct ETCP_LINK* next = link->next; + etcp_link_close(link); + link = next; + } + etcp->links = NULL; + } + + // Drain and free all queues drain_and_free_queue(&etcp->input_queue); drain_and_free_queue(&etcp->output_queue); drain_and_free_queue(&etcp->input_send_q); drain_and_free_queue(&etcp->input_wait_ack); drain_and_free_queue(&etcp->recv_q); drain_and_free_queue(&etcp->ack_q); - - // Drain and free ack_q (contains ACK_PACKET from ack_pool - special handling) - if (etcp->ack_q) { - struct ACK_PACKET* pkt; - while ((pkt = (struct ACK_PACKET*)queue_data_get(etcp->ack_q)) != NULL) { - queue_entry_free((struct ll_entry*)pkt); - } - queue_free(etcp->ack_q); - etcp->ack_q = NULL; - } // Free memory pools after all elements are returned if (etcp->inflight_pool) { @@ -331,17 +334,6 @@ void etcp_connection_close(struct ETCP_CONN* etcp) { etcp->io_pool = NULL; } - // Clear links list safely - if (etcp->links) { - struct ETCP_LINK* link = etcp->links; - while (link) { - struct ETCP_LINK* next = link->next; - etcp_link_close(link); - link = next; - } - etcp->links = NULL; - } - u_free(etcp->name); // Clear next pointer to prevent dangling references