diff --git a/lib/std/Build/Cache.zig b/lib/std/Build/Cache.zig index b3283856d9e64339cbaf153601aa80a0265bcefb..54f0b8baad329214e94a37d56173f04d04c4d082 100644 --- a/lib/std/Build/Cache.zig +++ b/lib/std/Build/Cache.zig @@ -1007,6 +1007,8 @@ pub const Manifest = struct { keep = try addPrefixedPathPost(self, prefixed_path); } + /// Low level function. `prefixed_path` references cloned memory. Returns + /// whether or not `prefixed_path.sub_path` should be kept. pub fn addPrefixedPathPost(man: *Manifest, prefixed_path: PrefixedPath) !bool { assert(man.manifest_file != null); const gpa = man.cache.gpa; diff --git a/lib/std/zig.zig b/lib/std/zig.zig index 6efe0cc7431e367f19add7b142db99641e6728b7..657b05638e03147e5d54d51b3768b97004333276 100644 --- a/lib/std/zig.zig +++ b/lib/std/zig.zig @@ -1754,8 +1754,10 @@ pub fn buildExeSubprocess(gpa: Allocator, io: Io, options: BuildExeSubprocessOpt var it = mem.splitScalar(u8, body, 0); while (it.next()) |prefixed_path| { const prefix: Server.Message.PathPrefix = @enumFromInt(prefixed_path[0] - 1); - const sub_path = prefixed_path[1..]; - _ = man.addPrefixedPathPost(.{ + const sub_path = try gpa.dupe(u8, prefixed_path[1..]); + var keep = false; + defer if (!keep) gpa.free(sub_path); + keep = man.addPrefixedPathPost(.{ .prefix = @intFromEnum(prefix), .sub_path = sub_path, }) catch |err| switch (err) {