diff --git a/lib/compiler/Maker/PkgConfig.zig b/lib/compiler/Maker/PkgConfig.zig index 56bf8f08d721aee1cfd0e678cc8f320e3b540d98..5ef34a8fbce44001dc822d37d55f11fd1a636e48 100644 --- a/lib/compiler/Maker/PkgConfig.zig +++ b/lib/compiler/Maker/PkgConfig.zig @@ -104,6 +104,7 @@ fn getPkgs( else => |e| return e, }; + step.clearFailedCommand(maker.gpa); pc.pkgs = result; return result; } diff --git a/lib/compiler/Maker/Step/Run.zig b/lib/compiler/Maker/Step/Run.zig index 326048b4a1a9d5c8b7203f7c6256d67899247ed4..8b30753ecacc8b25c016286f6b110c13ed6f318c 100644 --- a/lib/compiler/Maker/Step/Run.zig +++ b/lib/compiler/Maker/Step/Run.zig @@ -332,6 +332,12 @@ pub fn make( try populateGeneratedStdIo(maker, &conf_run, cache_root, &digest); try populateGeneratedPaths(maker, output_placeholders.items, cache_root, &digest); + + // The utility functions that spawn the child process must unconditionally allocate + // the failed command because at that point it is not known whether the step will + // pass or fail based on the process termination. Here we free the memory since + // the step has succeeded. + step.clearFailedCommand(gpa); } /// Reads stdout of a Zig test process until a termination condition is reached: @@ -2148,7 +2154,11 @@ fn spawnChildAndCollect( .dir => unreachable, .inherit => null, }; - errdefer step.setFailedCommand(gpa, argv, .{ + // We have to set the failed command here regardless of whether this + // function returns an error because only after this function returns + // does the logic determine whether the child process termination was + // success or failure. + step.setFailedCommand(gpa, argv, .{ .cwd = cwd_string, .child_env = environ_map, .parent_env = &graph.environ_map,