authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-08 20:52:02-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-08 20:52:02-07:00
log1b702f8ddb11d53b53de8350323fd14b85d58caf
tree475daa28f8bb18603b0f064c7e0bf809ed2c9b6c
parent61b868f9a5345ab1dba3395107c7cdee3fd2989e

stage2: fix the memory leaks


2 files changed, 15 insertions(+), 0 deletions(-)

src/Module.zig+14
......@@ -2292,6 +2292,20 @@ pub const InnerError = error{ OutOfMemory, AnalysisFail };
22922292pub fn deinit(mod: *Module) void {
22932293 const gpa = mod.gpa;
22942294
2295 // The callsite of `Compilation.create` owns the `root_pkg`, however
2296 // Module owns the builtin and std packages that it adds.
2297 if (mod.root_pkg.table.remove("builtin")) |entry| {
2298 gpa.free(entry.key);
2299 entry.value.destroy(gpa);
2300 }
2301 if (mod.root_pkg.table.remove("std")) |entry| {
2302 gpa.free(entry.key);
2303 entry.value.destroy(gpa);
2304 }
2305 if (mod.root_pkg.table.remove("root")) |entry| {
2306 gpa.free(entry.key);
2307 }
2308
22952309 mod.compile_log_text.deinit(gpa);
22962310
22972311 mod.zig_cache_artifact_directory.handle.close();
src/test.zig+1
......@@ -624,6 +624,7 @@ pub const TestContext = struct {
624624 .root_src_path = tmp_src_path,
625625 .namespace_hash = Package.root_namespace_hash,
626626 };
627 defer root_pkg.table.deinit(allocator);
627628
628629 const bin_name = try std.zig.binNameAlloc(arena, .{
629630 .root_name = "test_case",