Repository navigation
Commit e548d97
committed
fix(mcp): free the empty name-lookup result before trace_path's QN fallback
handle_trace_call_path first looks the function up by bare name
(cbm_store_find_nodes_by_name). find_nodes_generic allocates its
initial 16-slot array before stepping the statement and hands it back
even when zero rows match. When the bare name misses and the
qualified_name fallback then resolves the node, the handler overwrote
`nodes` with a fresh one-element array, leaking the empty 1 KB array
on every trace_path call made with a qualified name - for the whole
lifetime of the daemon. The malloc-failure branch of the fallback lost
the same array.
Release the zero-row array before the fallback replaces the pointer.
The other find_nodes_* callers (get_code_snippet outline, search_code
grep classification, detect_changes seeding, Cypher label scans)
already free the container on zero rows; the not-found path in this
handler did too.
Proof (macOS leak lane, Homebrew clang 22.1.8,
`make -f Makefile.cbm test-lsan LSAN_SUITES=mcp`):
- with the new test, without the fix: 322 passed, then
"ERROR: LeakSanitizer: detected memory leaks - Direct leak of 1024
byte(s) in 1 object(s) allocated from find_nodes_generic store.c:2771
<- handle_trace_call_path mcp.c:9176 <-
test_tool_trace_call_path_qn_fallback_frees_name_miss", exit 1
(the only leak in the suite).
- with the fix: 322 passed, 4 skipped, no leak report, exit 0.
The new test pins its own precondition (the bare-name lookup of the
qualified name returns zero rows) and that the trace resolves through
the fallback, so it keeps exercising this path. LSan (default-on under
Linux ASan, test-lsan on macOS) turns any regression red.
Found while attributing CI on DeusData#2305.
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>1 parent 80eb92a commit e548d97
2 files changed
Lines changed: 65 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9178 | 9178 | | |
9179 | 9179 | | |
9180 | 9180 | | |
| 9181 | + | |
| 9182 | + | |
| 9183 | + | |
9181 | 9184 | | |
9182 | 9185 | | |
9183 | 9186 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7187 | 7187 | | |
7188 | 7188 | | |
7189 | 7189 | | |
| 7190 | + | |
| 7191 | + | |
| 7192 | + | |
| 7193 | + | |
| 7194 | + | |
| 7195 | + | |
| 7196 | + | |
| 7197 | + | |
| 7198 | + | |
| 7199 | + | |
| 7200 | + | |
| 7201 | + | |
| 7202 | + | |
| 7203 | + | |
| 7204 | + | |
| 7205 | + | |
| 7206 | + | |
| 7207 | + | |
| 7208 | + | |
| 7209 | + | |
| 7210 | + | |
| 7211 | + | |
| 7212 | + | |
| 7213 | + | |
| 7214 | + | |
| 7215 | + | |
| 7216 | + | |
| 7217 | + | |
| 7218 | + | |
| 7219 | + | |
| 7220 | + | |
| 7221 | + | |
| 7222 | + | |
| 7223 | + | |
| 7224 | + | |
| 7225 | + | |
| 7226 | + | |
| 7227 | + | |
| 7228 | + | |
| 7229 | + | |
| 7230 | + | |
| 7231 | + | |
| 7232 | + | |
| 7233 | + | |
| 7234 | + | |
| 7235 | + | |
| 7236 | + | |
| 7237 | + | |
| 7238 | + | |
| 7239 | + | |
| 7240 | + | |
| 7241 | + | |
| 7242 | + | |
| 7243 | + | |
| 7244 | + | |
| 7245 | + | |
| 7246 | + | |
| 7247 | + | |
| 7248 | + | |
| 7249 | + | |
| 7250 | + | |
7190 | 7251 | | |
7191 | 7252 | | |
7192 | 7253 | | |
| |||
20638 | 20699 | | |
20639 | 20700 | | |
20640 | 20701 | | |
| 20702 | + | |
20641 | 20703 | | |
20642 | 20704 | | |
20643 | 20705 | | |
| |||
0 commit comments