szn

Bug 81 — errdefer reads uninitialized fd if socket() fails

81. errdefer reads uninitialized fd if socket() fails

File: src/client/connect.zig:22–23 Severity: MEDIUM Status: ✅ FIXED — split into separate c.socket call and try mapErr; fd only assigned on success so errdefer never fires on error path. Unit tests added.

const fd = try mapErr(c.socket(c.AF.UNIX, c.SOCK.STREAM, 0));
errdefer _ = c.close(fd);

If c.socket returns -1, mapErr propagates the error — but fd was never assigned because the const initialisation failed. The errdefer reads an uninitialized i32. UB.