aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-04-08 20:52:02 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-04-08 20:52:02 -0700
commit1b702f8ddb11d53b53de8350323fd14b85d58caf (patch)
tree475daa28f8bb18603b0f064c7e0bf809ed2c9b6c /src
parent61b868f9a5345ab1dba3395107c7cdee3fd2989e (diff)
downloadzig-1b702f8ddb11d53b53de8350323fd14b85d58caf.tar.gz
zig-1b702f8ddb11d53b53de8350323fd14b85d58caf.zip
stage2: fix the memory leaks
Diffstat (limited to 'src')
-rw-r--r--src/Module.zig14
-rw-r--r--src/test.zig1
2 files changed, 15 insertions, 0 deletions
diff --git a/src/Module.zig b/src/Module.zig
index 8da9a6dbdc..af3a04fe98 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -2292,6 +2292,20 @@ pub const InnerError = error{ OutOfMemory, AnalysisFail };
pub fn deinit(mod: *Module) void {
const gpa = mod.gpa;
+ // The callsite of `Compilation.create` owns the `root_pkg`, however
+ // Module owns the builtin and std packages that it adds.
+ if (mod.root_pkg.table.remove("builtin")) |entry| {
+ gpa.free(entry.key);
+ entry.value.destroy(gpa);
+ }
+ if (mod.root_pkg.table.remove("std")) |entry| {
+ gpa.free(entry.key);
+ entry.value.destroy(gpa);
+ }
+ if (mod.root_pkg.table.remove("root")) |entry| {
+ gpa.free(entry.key);
+ }
+
mod.compile_log_text.deinit(gpa);
mod.zig_cache_artifact_directory.handle.close();
diff --git a/src/test.zig b/src/test.zig
index 1ffbba535d..f57708746a 100644
--- a/src/test.zig
+++ b/src/test.zig
@@ -624,6 +624,7 @@ pub const TestContext = struct {
.root_src_path = tmp_src_path,
.namespace_hash = Package.root_namespace_hash,
};
+ defer root_pkg.table.deinit(allocator);
const bin_name = try std.zig.binNameAlloc(arena, .{
.root_name = "test_case",