authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-24 17:27:59-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-29 23:50:20-07:00
log519a47af31b0eaf41fc3649474e16f460b454795
treecfceb0dc19fd1a20c47c762ec5da8c52eea8abf8
parent09f61b13b359eec02d12567b3bd2c967c5448e81

Maker: fix memory leak of deps hash tables

This is still basically a leak since it uses global arena but it can be adjusted later to use an arena local to the while loop iteration as part of a larger global audit.

1 files changed, 2 insertions(+), 4 deletions(-)

lib/compiler/Maker.zig+2-4
......@@ -716,14 +716,12 @@ pub fn main(init: process.Init.Minimal) !void {
716716 .name = "@build",
717717 .root_path = try root_build_src_path.toString(arena),
718718 };
719 defer build_mod.deps.deinit(gpa);
720719
721720 const deps_mod = try arena.create(CliModule);
722721 deps_mod.* = .{
723722 .name = "@dependencies",
724723 .root_path = undefined,
725724 };
726 defer deps_mod.deps.deinit(gpa);
727725
728726 // This loop is re-evaluated when the build script exits with an indication that it
729727 // could not continue due to missing lazy dependencies.
......@@ -876,7 +874,7 @@ pub fn main(init: process.Init.Minimal) !void {
876874 // Add a CliModule for each package's build.zig.
877875 const hashes = job_queue.table.keys();
878876 const fetches = job_queue.table.values();
879 try deps_mod.deps.ensureUnusedCapacity(gpa, @intCast(hashes.len));
877 try deps_mod.deps.ensureUnusedCapacity(arena, @intCast(hashes.len));
880878 for (hashes, fetches) |*hash, f| {
881879 if (f == &fetch) {
882880 // The first one is a dummy package for the current project.
......@@ -902,7 +900,7 @@ pub fn main(init: process.Init.Minimal) !void {
902900 if (!f.have_manifest) continue;
903901 const man = &f.manifest;
904902 const dep_names = man.dependencies.keys();
905 try mod.deps.ensureUnusedCapacity(gpa, @intCast(dep_names.len));
903 try mod.deps.ensureUnusedCapacity(arena, @intCast(dep_names.len));
906904 for (dep_names, man.dependencies.values()) |name, dep| {
907905 const dep_digest = Package.Fetch.depDigest(
908906 f.package_root,