Skip to content

Commit e6638a7

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 fb8d14f commit e6638a7

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

‎src/mcp/mcp.c‎

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

72477247
yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);
72487248
yyjson_mut_val *root = doc ? yyjson_mut_obj(doc) : NULL;
7249-
if (!root) {
7250-
yyjson_mut_doc_free(doc);
7251-
free(project);
7252-
return mcp_result_from_json(args, NULL);
7249+
/* A failed allocation or report answers with the MCP allocation-error
7250+
* response, through the one exit below. */
7251+
bool failed = !root;
7252+
if (root) {
7253+
yyjson_mut_doc_set_root(doc, root);
72537254
}
7254-
yyjson_mut_doc_set_root(doc, root);
72557255

7256-
if (project) {
7256+
if (failed) {
7257+
/* nothing to report into */
7258+
} else if (project) {
72577259
int nodes = cbm_store_count_nodes(store, project);
72587260
int edges = cbm_store_count_edges(store, project);
72597261
/* A negative count is a failed read (CBM_STORE_ERR), not a small
@@ -7287,11 +7289,8 @@ static char *handle_index_status(cbm_mcp_server_t *srv, const char *args) {
72877289
safe_str_free(&proj_info.indexed_at);
72887290
safe_str_free(&proj_info.root_path);
72897291
if (!doc_links_built) {
7290-
yyjson_mut_doc_free(doc);
7291-
free(project);
7292-
return mcp_result_from_json(args, NULL);
7293-
}
7294-
if (counts_unreadable) {
7292+
failed = true;
7293+
} else if (counts_unreadable) {
72957294
const char *hint;
72967295
if (nodes < 0 && edges < 0) {
72977296
hint = "The nodes and edges tables could not be read; the database may be "
@@ -7314,7 +7313,7 @@ static char *handle_index_status(cbm_mcp_server_t *srv, const char *args) {
73147313
yyjson_mut_obj_add_str(doc, root, "status", "no_project");
73157314
}
73167315

7317-
char *json = yy_doc_to_str(doc);
7316+
char *json = failed ? NULL : yy_doc_to_str(doc);
73187317
yyjson_mut_doc_free(doc);
73197318
free(project);
73207319

0 commit comments

Comments
 (0)