Skip to content

fix(cloud-tools): add defer free for stdout allocation in cloud_tools.zig #173

@gHashTag

Description

@gHashTag

Task

In tools/mcp/trinity_mcp/cloud_tools.zig, the runTriCloud() function allocates stdout via readToEndAlloc() but never frees it — memory leak on every MCP tool call.

Current Code (around line 86)

const stdout = child.stdout.?.readToEndAlloc(std.heap.page_allocator, MAX_OUTPUT) catch {
    return copyToBuf(buf, "Error: Failed to read output");
};
// stdout is NEVER freed!

Fix

Add defer std.heap.page_allocator.free(stdout); immediately after the allocation:

const stdout = child.stdout.?.readToEndAlloc(std.heap.page_allocator, MAX_OUTPUT) catch {
    return copyToBuf(buf, "Error: Failed to read output");
};
defer std.heap.page_allocator.free(stdout);

File

  • tools/mcp/trinity_mcp/cloud_tools.zig — around line 86

Acceptance

  • zig build compiles without errors
  • zig fmt passes
  • defer free present after readToEndAlloc

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