szn

Bug 120 — log.zig — Data race on log_fd and log_fd_failed globals

120. log.zig — Data race on log_fd and log_fd_failed globals

File: src/log.zig:31–32, 94–107 Severity: MEDIUM Status: ✅ FIXED — log_fd_failed changed to std.atomic.Value(bool). All reads/writes use .load(.seq_cst) / .store(.seq_cst).

var log_fd: ?std.posix.fd_t = null;
var log_fd_failed: bool = false;

These globals are read/written without synchronization. log_enabled uses atomics, but log_fd and log_fd_failed don’t. Multiple threads calling logFn concurrently can both see log_fd == null, both open the file, and one fd leaks. Worse, enable()/disable() can close an fd while another thread is writing to it.