diff --git a/lib/compiler/Maker.zig b/lib/compiler/Maker.zig index 7eac68eebb7bd09afb8cac07d6ab1e688e6c4bc1..5c7f4a94d4eeee79ef158262a5b51508c93bd0c3 100644 --- a/lib/compiler/Maker.zig +++ b/lib/compiler/Maker.zig @@ -63,9 +63,9 @@ protocol_server_mutex: Io.Mutex, web_server: ?*AvoidableWebServer, /// Allocated into `gpa`. memory_blocked_steps: std.ArrayList(Configuration.Step.Index), -/// Allocated into `gpa`. +/// Allocated into `gpa` during `prepare`. initial_steps: std.array_hash_map.Auto(Configuration.Step.Index, void), -/// Allocated into `gpa`. +/// Allocated into `gpa` during `prepare`. step_stack: std.array_hash_map.Auto(Configuration.Step.Index, void), pkg_config: PkgConfig, @@ -762,10 +762,8 @@ pub fn main(init: process.Init.Minimal) !void { .include = install_include_path, }, - // Extra step at the end which is the autogenerated placeholder - // step which indicates that we need to reconfigure. - .steps = try arena.alloc(Step, scanned_config.configuration.steps.len + 1), - .generated_files = try arena.alloc(Path, scanned_config.configuration.generated_files_len), + .steps = &.{}, + .generated_files = &.{}, .run_args = run_args, .available_rss = max_rss, @@ -792,11 +790,7 @@ pub fn main(init: process.Init.Minimal) !void { else .failures, }; - defer { - maker.memory_blocked_steps.deinit(gpa); - maker.initial_steps.deinit(gpa); - maker.step_stack.deinit(gpa); - } + defer maker.deinit(); if (maker.available_rss == 0) { maker.available_rss = process.totalSystemMemory() catch std.math.maxInt(u64); @@ -863,6 +857,9 @@ pub fn main(init: process.Init.Minimal) !void { &watch.?, if (in_debounce) .{ .ms = debounce_interval_ms } else .none, }); + } else if (watch) |*w| { + w.deinit(); + watch = null; } continue :loop try select.await(); @@ -915,7 +912,7 @@ pub fn main(init: process.Init.Minimal) !void { if (!Watch.have_impl) fatal("--watch not yet implemented for {t}", .{native_os}); break :w try .init(&maker); }; - defer w.deinit(); + defer if (watch_flag) w.deinit(); if (web_server) |ws| try ws.updateConfiguration(&maker); @@ -2229,6 +2226,11 @@ fn prepare( const step_stack = &maker.step_stack; const c = &maker.scanned_config.configuration; + // Extra step at the end which is the autogenerated placeholder + // step which indicates that we need to reconfigure. + maker.steps = try arena.alloc(Step, c.steps.len + 1); + maker.generated_files = try arena.alloc(Path, c.generated_files_len); + // The last element is a reserved special pseudostep which contains the // watch inputs for the configurer executable. for (maker.steps[0 .. maker.steps.len - 1], 0..) |*step, step_index_usize| { @@ -2549,7 +2551,7 @@ fn makeSteps( }; if (code == 0) { removePoisonedConfiguration(io, maker.scanned_config); - if (debugMakerLeaks()) return deinit(maker); + if (debugMakerLeaks()) return; } cleanup_task.await(io); // There is a defer above but an exit below. _ = io.lockStderr(&.{}, graph.stderr_mode) catch {}; @@ -2558,12 +2560,10 @@ fn makeSteps( fn deinit(maker: *Maker) void { const gpa = maker.gpa; - for (maker.steps) |*step| { - step.clearResultStderr(gpa); - step.clearFailedCommand(gpa); - step.clearErrorBundle(gpa); - step.inputs.deinit(gpa); - } + for (maker.steps) |*step| step.deinit(gpa); + maker.memory_blocked_steps.deinit(gpa); + maker.initial_steps.deinit(gpa); + maker.step_stack.deinit(gpa); } fn stepReady( diff --git a/lib/compiler/Maker/Step.zig b/lib/compiler/Maker/Step.zig index 0fd82226cce06989c0acea46f4f22e4dcd6d6e58..fcb60233f0f8f458e146b4a71bae60ddd8525c9b 100644 --- a/lib/compiler/Maker/Step.zig +++ b/lib/compiler/Maker/Step.zig @@ -309,6 +309,15 @@ pub fn make( } } +pub fn deinit(step: *Step, gpa: Allocator) void { + step.clearResultStderr(gpa); + step.clearFailedCommand(gpa); + step.clearErrorBundle(gpa); + step.inputs.deinit(gpa); + if (step.getZigProcess()) |zp| gpa.destroy(zp); + step.* = undefined; +} + /// Prepares the step for being re-evaluated. pub fn reset(step: *Step, maker: *Maker) void { assert(step.state == .precheck_done);