From 64645e14013bd7bf0c96d920e15a45456215ef2c Mon Sep 17 00:00:00 2001 From: Yorgos Thessalonikefs Date: Wed, 24 Sep 2025 14:30:24 +0200 Subject: [PATCH] - Avoid calling mesh_detect_cycle_found() when there is no mesh state to begin with. --- doc/Changelog | 4 ++++ services/mesh.c | 16 ++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/doc/Changelog b/doc/Changelog index 579eaf81b..110e0f95c 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,7 @@ +24 September 2025: Yorgos + - Avoid calling mesh_detect_cycle_found() when there is no mesh state + to begin with. + 23 September 2025: Yorgos - Merge #1352 from Petr Vaganov: pythonmod: fix HANDLE_LEAK on pythonmod_init. diff --git a/services/mesh.c b/services/mesh.c index a0bb9ba2f..1a46ebb9b 100644 --- a/services/mesh.c +++ b/services/mesh.c @@ -1152,8 +1152,7 @@ mesh_detect_cycle_found(struct module_qstate* qstate, struct mesh_state* dep_m) { struct mesh_state* cyc_m = qstate->mesh_info; size_t counter = 0; - if(!dep_m) - return 0; + log_assert(dep_m); if(dep_m == cyc_m || find_in_subsub(dep_m, cyc_m, &counter)) { if(counter > MESH_MAX_SUBSUB) return 2; @@ -1197,10 +1196,6 @@ int mesh_add_sub(struct module_qstate* qstate, struct query_info* qinfo, struct mesh_area* mesh = qstate->env->mesh; *sub = mesh_area_find(mesh, NULL, qinfo, qflags, prime, valrec); - if(mesh_detect_cycle_found(qstate, *sub)) { - verbose(VERB_ALGO, "attach failed, cycle detected"); - return 0; - } if(!*sub) { #ifdef UNBOUND_DEBUG struct rbnode_type* n; @@ -1230,8 +1225,13 @@ int mesh_add_sub(struct module_qstate* qstate, struct query_info* qinfo, rbtree_insert(&mesh->run, &(*sub)->run_node); log_assert(n != NULL); *newq = &(*sub)->s; - } else + } else { *newq = NULL; + if(mesh_detect_cycle_found(qstate, *sub)) { + verbose(VERB_ALGO, "attach failed, cycle detected"); + return 0; + } + } return 1; } @@ -2297,7 +2297,7 @@ mesh_detect_cycle(struct module_qstate* qstate, struct query_info* qinfo, struct mesh_area* mesh = qstate->env->mesh; struct mesh_state* dep_m = NULL; dep_m = mesh_area_find(mesh, NULL, qinfo, flags, prime, valrec); - return mesh_detect_cycle_found(qstate, dep_m); + return dep_m?mesh_detect_cycle_found(qstate, dep_m):0; } void mesh_list_insert(struct mesh_state* m, struct mesh_state** fp, -- 2.47.3