diff --git a/src/mcp.c b/src/mcp.c index d2a8231..8b43a81 100644 --- a/src/mcp.c +++ b/src/mcp.c @@ -502,7 +502,15 @@ static int stdio_exchange(const j_mcp *m, const char *body, mcp_resp *out, doubl if (!st->ready) { if (st->pid > 0) stdio_stop(st); int in_pipe[2], out_pipe[2]; - if (pipe(in_pipe) != 0 || pipe(out_pipe) != 0) { + if (pipe(in_pipe) != 0) { + pthread_mutex_unlock(&st->mu); + return -1; + } + /* The second pipe can fail on its own; the first one's two fds are + * already open and leaked on that path (the analyzer found it). */ + if (pipe(out_pipe) != 0) { + close(in_pipe[0]); + close(in_pipe[1]); pthread_mutex_unlock(&st->mu); return -1; }