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 {...@@ -716,14 +716,12 @@ pub fn main(init: process.Init.Minimal) !void {
716 .name = "@build",716 .name = "@build",
717 .root_path = try root_build_src_path.toString(arena),717 .root_path = try root_build_src_path.toString(arena),
718 };718 };
719 defer build_mod.deps.deinit(gpa);
720719
721 const deps_mod = try arena.create(CliModule);720 const deps_mod = try arena.create(CliModule);
722 deps_mod.* = .{721 deps_mod.* = .{
723 .name = "@dependencies",722 .name = "@dependencies",
724 .root_path = undefined,723 .root_path = undefined,
725 };724 };
726 defer deps_mod.deps.deinit(gpa);
727725
728 // This loop is re-evaluated when the build script exits with an indication that it726 // This loop is re-evaluated when the build script exits with an indication that it
729 // could not continue due to missing lazy dependencies.727 // could not continue due to missing lazy dependencies.
...@@ -876,7 +874,7 @@ pub fn main(init: process.Init.Minimal) !void {...@@ -876,7 +874,7 @@ pub fn main(init: process.Init.Minimal) !void {
876 // Add a CliModule for each package's build.zig.874 // Add a CliModule for each package's build.zig.
877 const hashes = job_queue.table.keys();875 const hashes = job_queue.table.keys();
878 const fetches = job_queue.table.values();876 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));
880 for (hashes, fetches) |*hash, f| {878 for (hashes, fetches) |*hash, f| {
881 if (f == &fetch) {879 if (f == &fetch) {
882 // The first one is a dummy package for the current project.880 // The first one is a dummy package for the current project.
...@@ -902,7 +900,7 @@ pub fn main(init: process.Init.Minimal) !void {...@@ -902,7 +900,7 @@ pub fn main(init: process.Init.Minimal) !void {
902 if (!f.have_manifest) continue;900 if (!f.have_manifest) continue;
903 const man = &f.manifest;901 const man = &f.manifest;
904 const dep_names = man.dependencies.keys();902 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));
906 for (dep_names, man.dependencies.values()) |name, dep| {904 for (dep_names, man.dependencies.values()) |name, dep| {
907 const dep_digest = Package.Fetch.depDigest(905 const dep_digest = Package.Fetch.depDigest(
908 f.package_root,906 f.package_root,