From d8089f8d1208ed264bd502a142f0906f17bd9eb7 Mon Sep 17 00:00:00 2001 From: evgeny Date: Sat, 24 Oct 2026 14:56:23 +0200 Subject: [PATCH] Release router unit fixture registry ownership completely --- tests/test_etcp_router_unit.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tests/test_etcp_router_unit.c b/tests/test_etcp_router_unit.c index 01902c34..58d5dbdf 100644 --- a/tests/test_etcp_router_unit.c +++ b/tests/test_etcp_router_unit.c @@ -5,8 +5,7 @@ #include #include #include -#include -#include +#include "../lib/platform_compat.h" #include "etcp.h" #include "etcp_api.h" @@ -213,6 +212,7 @@ static int setup_sign_keys(void) { static void setup_bgp_for_sign_test(struct UTUN_INSTANCE* inst, int with_ed25519_key) { inst->topo_groups = u_calloc(1, sizeof(struct TOPO_GROUPS)); if (!inst->topo_groups) { printf(" setup_bgp: topo_groups alloc failed\n"); return; } + inst->topo_groups->instance = inst; inst->topo_groups->group_list = queue_new(inst->ua, 16, 0, 8, "group_list_test"); inst->topo_groups->node_registry = queue_new(inst->ua, BGP_NODES_HASH_SIZE, 0, 8, "node_registry_test"); @@ -232,7 +232,7 @@ static void setup_bgp_for_sign_test(struct UTUN_INSTANCE* inst, int with_ed25519 nq->ll.size = sizeof(struct TOPO_GROUP_NODE) - sizeof(struct ll_entry); struct TOPO_NODE* ni = u_calloc(1, sizeof(struct TOPO_NODE)); if (!ni) { printf(" setup_bgp: ni alloc failed\n"); u_free(nq); return; } - ni->group_ref_count = 1; ni->node_id = SIGNER_NODE; + ni->node_id = SIGNER_NODE; if (with_ed25519_key) memcpy(ni->ed25519_public_key, g_sign_ed25519_pubkey, SC_PUBKEY_SIZE); topo_node_registry_store(inst->topo_groups, ni); nq->node_id = ni->node_id; @@ -244,13 +244,17 @@ static void teardown_bgp_for_sign_test(struct UTUN_INSTANCE* inst) { struct TOPO_GROUP* group = topo_groups_get_default(inst->topo_groups); if (group && group->nodes) { struct ll_entry* e; - while ((e = queue_data_get(group->nodes)) != NULL) queue_entry_free(e); + while ((e = queue_data_get(group->nodes)) != NULL) { + topo_nodeq_free_group_fields(inst->topo_groups, (struct TOPO_GROUP_NODE*)e); + queue_entry_free(e); + } queue_free(group->nodes); group->nodes = NULL; } struct ll_entry* ge; while ((ge = queue_data_get(inst->topo_groups->group_list)) != NULL) queue_entry_free(ge); queue_free(inst->topo_groups->group_list); + queue_free(inst->topo_groups->node_registry); u_free(inst->topo_groups); inst->topo_groups = NULL; } @@ -1110,7 +1114,7 @@ static void setup_bgp_for_e2e_test(struct UTUN_INSTANCE* inst, int register_peer if (register_peer) { struct TOPO_NODE* ni = u_calloc(1, sizeof(struct TOPO_NODE)); if (!ni) return; - ni->group_ref_count = 1; ni->node_id = E2E_PEER_NODE; + ni->node_id = E2E_PEER_NODE; memcpy(ni->public_key, g_e2e_peer_keys.public_key, SC_PUBKEY_SIZE); topo_node_registry_store(inst->topo_groups, ni); } @@ -1127,8 +1131,10 @@ static void setup_bgp_for_e2e_test(struct UTUN_INSTANCE* inst, int register_peer static void teardown_bgp_for_e2e_test(struct UTUN_INSTANCE* inst) { if (!inst || !inst->topo_groups) return; if (inst->topo_groups->node_registry) { - struct ll_entry* e; - while ((e = queue_data_get(inst->topo_groups->node_registry)) != NULL) queue_entry_free(e); + while (inst->topo_groups->node_registry->head) { + uint64_t node_id; memcpy(&node_id, inst->topo_groups->node_registry->head->data, sizeof(node_id)); + topo_node_registry_unref(inst->topo_groups, node_id); + } queue_free(inst->topo_groups->node_registry); inst->topo_groups->node_registry = NULL; } @@ -1575,6 +1581,7 @@ static int test_loopback_length_and_errors(void) { } int main(void) { + size_t allocated_before = u_get_allocated_count(); // Run all tests test_close_group_from_close_callback(); test_reopen_from_close_callback(); @@ -1627,6 +1634,10 @@ int main(void) { test_e2e_combined_signed(); } + if (u_get_allocated_count() != allocated_before) { + DEBUG_ERROR(DEBUG_CATEGORY_ETCPROUTE, "router unit retained allocations: before=%zu after=%zu", + allocated_before, (size_t)u_get_allocated_count()); test_failed++; + } printf("\n=== Results: %d/%d passed, %d failed ===\n", test_passed, test_total, test_failed); return test_failed > 0 ? 1 : 0; }