11ccaf00b0c5

fix command-exit memory leaks: route all command allocations through an arena in main.zig, freed before main returns (per brief 3.3); NINA_DEBUG=1 nina hello now reports zero leaks

time
2026-06-04 23:16 UTC · 4 months ago
machine
koh2
agent
claude-opus-4-8
session
arena command allocations
parent
7d2118a61798
1 file src/main.zig+11 −3
src/main.zig+11 −3
@@ -28,6 +28,14 @@2828     const gpa = startup.gpa;2929     const io = startup.io;3030 31+    // Command allocations go through an arena freed when main returns. nina is a32+    // one-shot CLI that exits after one command, and std.process.exit skips33+    // defers, so per-allocation frees were easy to miss — the arena guarantees34+    // everything is released in one shot, eliminating exit-time leak reports.35+    var cmd_arena = std.heap.ArenaAllocator.init(gpa);36+    defer cmd_arena.deinit();37+    const ca = cmd_arena.allocator();38+3139     // Initialize output module with buffered stdout writer. Streaming (not the3240     // default positional) mode: stdout may be a terminal, pipe, or a redirected3341     // regular file. Positional mode pwrites from offset 0 and ignores the fd's@@ -57,7 +65,7 @@5765         const dummy_machine: types.Machine = .{ .name = "local", .local = true };5866         const dummy_cfg: types.NinaConfig = .{};5967         const pre_ctx = commands.Ctx{60-            .gpa = gpa,68+            .gpa = ca,6169             .io = io,6270             .environ = startup.environ_map,6371             .machine = dummy_machine,@@ -72,7 +80,7 @@7280             .json = args.json,7381         };7482         if (std.mem.eql(u8, args.command, "setup")) {75-            commands.setup(gpa, io, startup.environ_map) catch |err| {83+            commands.setup(ca, io, startup.environ_map) catch |err| {7684                 const msg = errors.error_info.getMessage() orelse errors.staticMessage(err);7785                 const detail = errors.error_info.getDetail();7886                 const suggestion = errors.error_info.getSuggestion();@@ -115,7 +123,7 @@115123     };116124 117125     const ctx = commands.Ctx{118-        .gpa = gpa,126+        .gpa = ca,119127         .io = io,120128         .environ = startup.environ_map,121129         .machine = machine,

view file