Skip to content

Commit d2ea04a

Browse files
committed
doc-links(core): index_status failure paths leave through its one exit
The doc_links report added two early returns to handle_index_status, each with its own free of the project name: raw allocator sites the memory-core ratchet does not allow (mcp.c went from 778 to 779 on this base). A failed allocation or report now sets a flag and leaves through the existing exit, which frees the name and answers with the MCP allocation-error response as before. The baseline of mcp.c is lowered to the 777 the ratchet now measures. Tests: doc_mentions (incl. the doc-link report fault injection), mcp pass; lint-memory-core passes. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 5283fe0 commit d2ea04a

2 files changed

Lines changed: 12 additions & 13 deletions

File tree

‎scripts/memory-core-baseline.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ src/git/git_context.c 18
5252
src/main.c 32
5353
src/mcp/compact_out.c 39
5454
src/mcp/index_supervisor.c 8
55-
src/mcp/mcp.c 778
55+
src/mcp/mcp.c 777
5656
src/pipeline/artifact.c 38
5757
src/pipeline/fqn.c 23
5858
src/pipeline/lsp_resolve.h 4

‎src/mcp/mcp.c‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7204,14 +7204,16 @@ static char *handle_index_status(cbm_mcp_server_t *srv, const char *args) {
72047204

72057205
yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);
72067206
yyjson_mut_val *root = doc ? yyjson_mut_obj(doc) : NULL;
7207-
if (!root) {
7208-
yyjson_mut_doc_free(doc);
7209-
free(project);
7210-
return mcp_result_from_json(args, NULL);
7207+
/* A failed allocation or report answers with the MCP allocation-error
7208+
* response, through the one exit below. */
7209+
bool failed = !root;
7210+
if (root) {
7211+
yyjson_mut_doc_set_root(doc, root);
72117212
}
7212-
yyjson_mut_doc_set_root(doc, root);
72137213

7214-
if (project) {
7214+
if (failed) {
7215+
/* nothing to report into */
7216+
} else if (project) {
72157217
int nodes = cbm_store_count_nodes(store, project);
72167218
int edges = cbm_store_count_edges(store, project);
72177219
/* A negative count is a failed read (CBM_STORE_ERR), not a small
@@ -7244,11 +7246,8 @@ static char *handle_index_status(cbm_mcp_server_t *srv, const char *args) {
72447246
safe_str_free(&proj_info.indexed_at);
72457247
safe_str_free(&proj_info.root_path);
72467248
if (!doc_links_built) {
7247-
yyjson_mut_doc_free(doc);
7248-
free(project);
7249-
return mcp_result_from_json(args, NULL);
7250-
}
7251-
if (counts_unreadable) {
7249+
failed = true;
7250+
} else if (counts_unreadable) {
72527251
const char *hint;
72537252
if (nodes < 0 && edges < 0) {
72547253
hint = "The nodes and edges tables could not be read; the database may be "
@@ -7271,7 +7270,7 @@ static char *handle_index_status(cbm_mcp_server_t *srv, const char *args) {
72717270
yyjson_mut_obj_add_str(doc, root, "status", "no_project");
72727271
}
72737272

7274-
char *json = yy_doc_to_str(doc);
7273+
char *json = failed ? NULL : yy_doc_to_str(doc);
72757274
yyjson_mut_doc_free(doc);
72767275
free(project);
72777276

0 commit comments

Comments
 (0)