Skip to content

Commit daea4b9

Browse files
Shidfarclaude
andcommitted
fix: address reviewer issues in cross_project_links handler
- Close sqlite3 handle on open_v2 failure (was leaking db handle) - Return cbm_mcp_text_result on malloc failure instead of NULL - Reduce safety break from 60000 to 58000 for memmove headroom Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d36f22a commit daea4b9

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/mcp/mcp.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3379,6 +3379,7 @@ static char *handle_cross_project_links(cbm_mcp_server_t *srv, const char *args)
33793379

33803380
sqlite3 *db = NULL;
33813381
if (sqlite3_open_v2(db_path, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
3382+
if (db) sqlite3_close(db);
33823383
return cbm_mcp_text_result(
33833384
"No cross-project links found. Index at least 2 projects first.", false);
33843385
}
@@ -3436,7 +3437,8 @@ static char *handle_cross_project_links(cbm_mcp_server_t *srv, const char *args)
34363437
/* Format output */
34373438
enum { XL_BUF_SIZE = 65536 };
34383439
char *buf = malloc(XL_BUF_SIZE);
3439-
if (!buf) { sqlite3_finalize(stmt); sqlite3_close(db); return NULL; }
3440+
if (!buf) { sqlite3_finalize(stmt); sqlite3_close(db);
3441+
return cbm_mcp_text_result("alloc failed", true); }
34403442
int pos = 0;
34413443
int total = 0;
34423444
char cur_protocol[64] = {0};
@@ -3472,7 +3474,7 @@ static char *handle_cross_project_links(cbm_mcp_server_t *srv, const char *args)
34723474
pcons ? pcons : "", qcons ? qcons : "", fcons ? fcons : "");
34733475
total++;
34743476

3475-
if (pos > 60000) break; /* safety limit */
3477+
if (pos > 58000) break; /* safety limit — leave headroom for header prepend */
34763478
}
34773479

34783480
sqlite3_finalize(stmt);

0 commit comments

Comments
 (0)