|
|
|
|
@ -338,23 +338,18 @@ int utun_instance_init(struct UTUN_INSTANCE *instance) {
|
|
|
|
|
// Note: TUN socket is already registered in tun_init()
|
|
|
|
|
|
|
|
|
|
// Initialize connections
|
|
|
|
|
// Добавляем прямой вывод для отладки проблемы double free
|
|
|
|
|
fprintf(stderr, "DEBUG: utun_instance_init() calling init_connections() for instance %p\n", instance); |
|
|
|
|
fflush(stderr); |
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "utun_instance_init() calling init_connections() for instance %p", instance); |
|
|
|
|
|
|
|
|
|
int conn_result = init_connections(instance); |
|
|
|
|
|
|
|
|
|
fprintf(stderr, "DEBUG: init_connections() returned: %d\n", conn_result); |
|
|
|
|
fflush(stderr); |
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "init_connections() returned: %d", conn_result); |
|
|
|
|
|
|
|
|
|
if (conn_result < 0) { |
|
|
|
|
fprintf(stderr, "DEBUG: Failed to initialize connections, returning error\n"); |
|
|
|
|
fflush(stderr); |
|
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "Failed to initialize connections, error=%d", conn_result); |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fprintf(stderr, "DEBUG: Connections initialized successfully, count=%d\n", instance->connections_count); |
|
|
|
|
fflush(stderr); |
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "Connections initialized successfully, count=%d", instance->connections_count); |
|
|
|
|
|
|
|
|
|
// Initialize control server if configured
|
|
|
|
|
if (instance->config->global.control_sock.ss_family != 0) { |
|
|
|
|
@ -416,54 +411,35 @@ void utun_instance_diagnose_leaks(struct UTUN_INSTANCE *instance, const char *ph
|
|
|
|
|
conn = conn->next; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
printf("\n🔍 [UTUN_INSTANCE LEAK DIAGNOSIS] Phase: %s\n", phase); |
|
|
|
|
printf(" Instance: %p\n", instance); |
|
|
|
|
printf(" Node ID: %llu\n", (unsigned long long)instance->node_id); |
|
|
|
|
printf(" UA instance: %p\n", instance->ua); |
|
|
|
|
printf(" Running: %d\n", instance->running); |
|
|
|
|
|
|
|
|
|
printf("\n📊 STRUCTURE COUNTS:\n"); |
|
|
|
|
printf(" ETCP Sockets: %d active\n", report.etcp_sockets_count); |
|
|
|
|
printf(" ETCP Connections: %d active\n", report.etcp_connections_count); |
|
|
|
|
printf(" ETCP Links: %d total\n", report.etcp_links_count); |
|
|
|
|
|
|
|
|
|
printf("\n🔧 RESOURCE STATUS:\n"); |
|
|
|
|
printf(" Memory Pool: %s\n", instance->pkt_pool ? "ALLOCATED" : "NULL"); |
|
|
|
|
printf(" TUN Interface: %s\n", instance->tun ? instance->tun->ifname : "NULL"); |
|
|
|
|
printf(" TUN FD: %d\n", instance->tun ? instance->tun->fd : -1); |
|
|
|
|
printf(" Connections list: %p\n", instance->connections); |
|
|
|
|
printf(" ETCP Sockets list: %p\n", instance->etcp_sockets); |
|
|
|
|
|
|
|
|
|
printf("\n⚠️ POTENTIAL LEAKS:\n"); |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "[LEAK DIAGNOSIS] Phase: %s", phase); |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "Instance: %p, Node ID: %llu, UA: %p, Running: %d", |
|
|
|
|
instance, (unsigned long long)instance->node_id, instance->ua, instance->running); |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "STRUCTURE COUNTS - ETCP Sockets: %d, ETCP Connections: %d, ETCP Links: %d", |
|
|
|
|
report.etcp_sockets_count, report.etcp_connections_count, report.etcp_links_count); |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "RESOURCE STATUS - Memory Pool: %s, TUN: %s, TUN FD: %d", |
|
|
|
|
instance->pkt_pool ? "ALLOCATED" : "NULL", |
|
|
|
|
instance->tun ? instance->tun->ifname : "NULL", |
|
|
|
|
instance->tun ? instance->tun->fd : -1); |
|
|
|
|
|
|
|
|
|
if (instance->pkt_pool) { |
|
|
|
|
printf(" ❌ Memory Pool not freed\n"); |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "POTENTIAL LEAK: Memory Pool not freed"); |
|
|
|
|
} |
|
|
|
|
if (instance->tun) { |
|
|
|
|
printf(" ❌ TUN interface not closed\n"); |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "POTENTIAL LEAK: TUN interface not closed"); |
|
|
|
|
} |
|
|
|
|
if (report.etcp_sockets_count > 0) { |
|
|
|
|
printf(" ❌ %d ETCP sockets still allocated\n", report.etcp_sockets_count); |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "POTENTIAL LEAK: %d ETCP sockets still allocated", report.etcp_sockets_count); |
|
|
|
|
} |
|
|
|
|
if (report.etcp_connections_count > 0) { |
|
|
|
|
printf(" ❌ %d ETCP connections still allocated\n", report.etcp_connections_count); |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "POTENTIAL LEAK: %d ETCP connections still allocated", report.etcp_connections_count); |
|
|
|
|
} |
|
|
|
|
if (report.etcp_links_count > 0) { |
|
|
|
|
printf(" ❌ %d ETCP links still allocated\n", report.etcp_links_count); |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "POTENTIAL LEAK: %d ETCP links still allocated", report.etcp_links_count); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
printf("\n📋 RECOMMENDATIONS:\n"); |
|
|
|
|
if (instance->pkt_pool) { |
|
|
|
|
printf(" → Call memory_pool_destroy() before freeing instance\n"); |
|
|
|
|
} |
|
|
|
|
if (instance->tun) { |
|
|
|
|
printf(" → Call tun_close() to close TUN interface\n"); |
|
|
|
|
} |
|
|
|
|
if (report.etcp_sockets_count > 0) { |
|
|
|
|
printf(" → Iterate and call etcp_socket_remove() for each socket\n"); |
|
|
|
|
} |
|
|
|
|
if (report.etcp_connections_count > 0) { |
|
|
|
|
printf(" → Iterate and call etcp_connection_close() for each connection\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
printf("\n"); |
|
|
|
|
|
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "[LEAK DIAGNOSIS] Recommendations: pkt_pool=%d, tun=%d, sockets=%d, connections=%d", |
|
|
|
|
instance->pkt_pool ? 1 : 0, |
|
|
|
|
instance->tun ? 1 : 0, |
|
|
|
|
report.etcp_sockets_count, |
|
|
|
|
report.etcp_connections_count); |
|
|
|
|
} |
|
|
|
|
|