Skip to content

fix(mcp-client): add child.deinit() in spawn error path in mcp_client.zig #166

@gHashTag

Description

@gHashTag

Task

In src/tri-api/mcp_client.zig around lines 53-68, the connectServer() function creates a Child process but if spawn fails, child.deinit() is never called — process resources leak.

Current Code

var child = std.process.Child.init(command, self.allocator);
child.stdin_behavior = .Pipe;
child.stdout_behavior = .Pipe;
child.stderr_behavior = .Ignore;

child.spawn() catch |err| {
    std.debug.print("[mcp] Failed to spawn {s}: {s}\n", .{ name, @errorName(err) });
    return 0;  // ← child never deinited
};

Fix

Add child.deinit() before the early return in the error path:

child.spawn() catch |err| {
    std.debug.print("[mcp] Failed to spawn {s}: {s}\n", .{ name, @errorName(err) });
    child.deinit();
    return 0;
};

File

  • src/tri-api/mcp_client.zig — around lines 53-68

Acceptance

  • zig build compiles without errors
  • zig fmt passes
  • child.deinit() called before early return in spawn error path

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent:spawnAuto-spawn agent container

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions