Skip to content

Commit 143ccfa

Browse files
committed
fix(ui): allocate the framework-entry flags through the memory core
The framework_entry flag array in cbm_layout_from_nodes was allocated with calloc and released with free on both exit paths. The memory-core linter counts raw allocator sites per file and fails when a file grows: src/ui/layout3d.c went from its baseline of 61 to 64. The array is owned entirely by this function, so allocation and both releases move together to the memory core: cbm_calloc and cbm_free with CBM_MEM_CLASS_OTHER, the same pairing this function already uses for out_calls. The route lookup's cbm_store_find_node_by_id result stays released by cbm_node_free_fields, the store API's own pair. src/ui/layout3d.c is back at 61 raw sites. The edge loop now sits one level deeper inside the new framework_entries_valid block, so it is re-indented to the house clang-format style. src/ui/ is outside the CI clang-format check, so this was done locally. Ignoring whitespace, the only changes are the three allocator lines and three re-wrapped lines. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent c4acff3 commit 143ccfa

1 file changed

Lines changed: 57 additions & 55 deletions

File tree

‎src/ui/layout3d.c‎

Lines changed: 57 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ cbm_layout_result_t *cbm_layout_from_nodes(cbm_store_t *store, const char *proje
575575

576576
/* 3. Query edges — filter during fetch via binary search (O(e log n)) */
577577
int *deg = calloc((size_t)n, sizeof(int));
578-
bool *framework_entry = calloc((size_t)n, sizeof(bool));
578+
bool *framework_entry = cbm_calloc(CBM_MEM_CLASS_OTHER, (size_t)n * sizeof(bool));
579579
int mapped = 0;
580580
int edge_cap = CBM_SZ_256;
581581
cbm_edge_t *all_edges = malloc((size_t)edge_cap * sizeof(cbm_edge_t));
@@ -586,62 +586,64 @@ cbm_layout_result_t *cbm_layout_from_nodes(cbm_store_t *store, const char *proje
586586
bool framework_entries_valid = deg && framework_entry && all_edges && es && ed;
587587
if (framework_entries_valid) {
588588
if (cbm_store_get_schema(store, project, &schema) == CBM_STORE_OK) {
589-
for (int t = 0; t < schema.edge_type_count; t++) {
590-
cbm_edge_t *te = NULL;
591-
int tc = 0;
592-
if (cbm_store_find_edges_by_type(store, project, schema.edge_types[t].type, &te, &tc) ==
593-
CBM_STORE_OK) {
594-
for (int e = 0; e < tc; e++) {
595-
int si = find_node_index(id_map, n, te[e].source_id);
596-
int di = find_node_index(id_map, n, te[e].target_id);
597-
if (si >= 0 && te[e].type && strcmp(te[e].type, "HANDLES") == 0) {
598-
cbm_node_t route = {0};
599-
if (cbm_store_find_node_by_id(store, te[e].target_id, &route) == CBM_STORE_OK) {
600-
if (route.label && strcmp(route.label, "Route") == 0)
601-
framework_entry[si] = true;
602-
cbm_node_free_fields(&route);
603-
} else
604-
framework_entries_valid = false;
605-
}
606-
if (si >= 0 && di >= 0) {
607-
if (mapped >= edge_cap) {
608-
int nc = edge_cap * PAIR_LEN;
609-
cbm_edge_t *te2 = realloc(all_edges, (size_t)nc * sizeof(cbm_edge_t));
610-
int *ts = realloc(es, (size_t)nc * sizeof(int));
611-
int *td = realloc(ed, (size_t)nc * sizeof(int));
612-
if (!te2 || !ts || !td) {
589+
for (int t = 0; t < schema.edge_type_count; t++) {
590+
cbm_edge_t *te = NULL;
591+
int tc = 0;
592+
if (cbm_store_find_edges_by_type(store, project, schema.edge_types[t].type, &te,
593+
&tc) == CBM_STORE_OK) {
594+
for (int e = 0; e < tc; e++) {
595+
int si = find_node_index(id_map, n, te[e].source_id);
596+
int di = find_node_index(id_map, n, te[e].target_id);
597+
if (si >= 0 && te[e].type && strcmp(te[e].type, "HANDLES") == 0) {
598+
cbm_node_t route = {0};
599+
if (cbm_store_find_node_by_id(store, te[e].target_id, &route) ==
600+
CBM_STORE_OK) {
601+
if (route.label && strcmp(route.label, "Route") == 0)
602+
framework_entry[si] = true;
603+
cbm_node_free_fields(&route);
604+
} else
613605
framework_entries_valid = false;
614-
if (te2)
615-
all_edges = te2;
616-
if (ts)
617-
es = ts;
618-
if (td)
619-
ed = td;
620-
free_edge_array(te + e, tc - e);
621-
goto edges_done;
606+
}
607+
if (si >= 0 && di >= 0) {
608+
if (mapped >= edge_cap) {
609+
int nc = edge_cap * PAIR_LEN;
610+
cbm_edge_t *te2 =
611+
realloc(all_edges, (size_t)nc * sizeof(cbm_edge_t));
612+
int *ts = realloc(es, (size_t)nc * sizeof(int));
613+
int *td = realloc(ed, (size_t)nc * sizeof(int));
614+
if (!te2 || !ts || !td) {
615+
framework_entries_valid = false;
616+
if (te2)
617+
all_edges = te2;
618+
if (ts)
619+
es = ts;
620+
if (td)
621+
ed = td;
622+
free_edge_array(te + e, tc - e);
623+
goto edges_done;
624+
}
625+
all_edges = te2;
626+
es = ts;
627+
ed = td;
628+
edge_cap = nc;
622629
}
623-
all_edges = te2;
624-
es = ts;
625-
ed = td;
626-
edge_cap = nc;
630+
all_edges[mapped] = te[e];
631+
memset(&te[e], 0, sizeof(cbm_edge_t));
632+
es[mapped] = si;
633+
ed[mapped] = di;
634+
deg[si]++;
635+
deg[di]++;
636+
mapped++;
637+
} else {
638+
free((void *)te[e].project);
639+
free((void *)te[e].type);
640+
free((void *)te[e].properties_json);
627641
}
628-
all_edges[mapped] = te[e];
629-
memset(&te[e], 0, sizeof(cbm_edge_t));
630-
es[mapped] = si;
631-
ed[mapped] = di;
632-
deg[si]++;
633-
deg[di]++;
634-
mapped++;
635-
} else {
636-
free((void *)te[e].project);
637-
free((void *)te[e].type);
638-
free((void *)te[e].properties_json);
639642
}
640-
}
641-
free(te);
642-
} else
643-
framework_entries_valid = false;
644-
}
643+
free(te);
644+
} else
645+
framework_entries_valid = false;
646+
}
645647
} else {
646648
framework_entries_valid = false;
647649
}
@@ -667,7 +669,7 @@ cbm_layout_result_t *cbm_layout_from_nodes(cbm_store_t *store, const char *proje
667669
if (!result || !bodies) {
668670
free(bodies);
669671
free(deg);
670-
free(framework_entry);
672+
cbm_free(CBM_MEM_CLASS_OTHER, framework_entry);
671673
free(es);
672674
free(ed);
673675
free(cdepth);
@@ -813,7 +815,7 @@ cbm_layout_result_t *cbm_layout_from_nodes(cbm_store_t *store, const char *proje
813815

814816
free(bodies);
815817
free(deg);
816-
free(framework_entry);
818+
cbm_free(CBM_MEM_CLASS_OTHER, framework_entry);
817819
free(es);
818820
free(ed);
819821
free(cdepth);

0 commit comments

Comments
 (0)