authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-23 23:50:35-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-29 23:50:19-07:00
logb4b92c71e551f6fdbc08879efe3650816bed1e14
tree5e60d6e197254f76acd143972bd6da814f6829ff
parenta69438f95cca0af4f3cc81237777e565c6b07efc

std.zig.buildExeSubprocess: fix memory management of file system inputs


2 files changed, 6 insertions(+), 2 deletions(-)

lib/std/Build/Cache.zig+2
......@@ -1007,6 +1007,8 @@ pub const Manifest = struct {
10071007 keep = try addPrefixedPathPost(self, prefixed_path);
10081008 }
10091009
1010 /// Low level function. `prefixed_path` references cloned memory. Returns
1011 /// whether or not `prefixed_path.sub_path` should be kept.
10101012 pub fn addPrefixedPathPost(man: *Manifest, prefixed_path: PrefixedPath) !bool {
10111013 assert(man.manifest_file != null);
10121014 const gpa = man.cache.gpa;
lib/std/zig.zig+4-2
......@@ -1754,8 +1754,10 @@ pub fn buildExeSubprocess(gpa: Allocator, io: Io, options: BuildExeSubprocessOpt
17541754 var it = mem.splitScalar(u8, body, 0);
17551755 while (it.next()) |prefixed_path| {
17561756 const prefix: Server.Message.PathPrefix = @enumFromInt(prefixed_path[0] - 1);
1757 const sub_path = prefixed_path[1..];
1758 _ = man.addPrefixedPathPost(.{
1757 const sub_path = try gpa.dupe(u8, prefixed_path[1..]);
1758 var keep = false;
1759 defer if (!keep) gpa.free(sub_path);
1760 keep = man.addPrefixedPathPost(.{
17591761 .prefix = @intFromEnum(prefix),
17601762 .sub_path = sub_path,
17611763 }) catch |err| switch (err) {