Files
lotherk c11a6c7989 mcp: join the server threads and give the tools an owner
The MCP plugin's reconnect thread was detached: shutdown killed the child and
returned, so the thread could still be reading into its line buffer (up to
16 MiB) and could call sp_host_add_tool() into a host that was being freed -- a
use-after-free waiting to happen, and the reason three leaks were suppressed in
tests/asan.supp (read_line, register_tools, connect_server).

Each server now keeps its pthread_t, init creates it joinable, and shutdown
waits (bounded, 5 s) for every thread to return before joining it and freeing
its state. teardown() frees the line buffer for the HTTP transport too (it was
freed only for stdio) and closes the stdio pipes even when the child was
already reaped.

The registered tools leaked for a second reason: sp_registry_add copies the
struct, not the strings, and sp_registry_free freed only the arrays -- the
prefixed name, the description, the printed schema and the toolref of every MCP
tool were lost with the registry. struct sp_tool gets a dispose hook; the
registry calls it for each tool, and the MCP plugin frees what it allocated (the
default schema is strdup'd now, so ownership is uniform). Builtins and the
gateway's tools leave it NULL; every positional initializer got the new field.

tests/asan.supp is empty. make check-asan: all 39 test binaries clean.
make check: all tests passed.
2026-11-19 00:05:05 +00:00

11 lines
588 B
Plaintext

# LeakSanitizer suppressions for `make check-asan`.
#
# Empty on purpose. The three entries that used to be here (read_line,
# register_tools, connect_server) were the MCP plugin's per-connection line
# buffer and the tools its reconnect thread registered: the thread was
# detached, so shutdown could not join it and freed nothing it might still
# touch. The thread now has a handle and a bounded join, teardown frees the
# line buffer for both transports, and the whole suite runs without a
# suppression. Add an entry here only with a comment that says why the leak
# cannot be fixed.