szn

Bug 123 — server/pty.zig — Memory leak on partial dupeZ failure in spawn

123. server/pty.zig — Memory leak on partial dupeZ failure in spawn

File: src/server/pty.zig:105–108 Severity: MEDIUM Status: ✅ FIXED — added @memset(argv_z, null) init and errdefer to free already-allocated strings if a later dupeZ fails.

var argv_z = try allocator.alloc(?[*:0]const u8, args.len + 1);
for (args, 0..) |arg, i| {
    argv_z[i] = try allocator.dupeZ(u8, arg);
}
argv_z[args.len] = null;

If dupeZ fails (OOM) at index i, the strings already allocated at indices 0..i are leaked. There is no errdefer to clean them up. The caller has no way to free them since argv_z is a local variable and the error propagates out.