From 8980f150e94f5542f5228e371fd2919a9922dc12 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 15 May 2020 18:54:48 -0400 Subject: [PATCH] fix memory leaks of one of the ZIR test cases --- src-self-hosted/ir.zig | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src-self-hosted/ir.zig b/src-self-hosted/ir.zig index cf2b65c71..2052479da 100644 --- a/src-self-hosted/ir.zig +++ b/src-self-hosted/ir.zig @@ -487,11 +487,13 @@ pub const Module = struct { .loaded_success => { allocator.free(self.source.bytes); self.contents.module.deinit(allocator); + allocator.destroy(self.contents.module); self.status = .unloaded_success; }, .loaded_sema_failure => { allocator.free(self.source.bytes); self.contents.module.deinit(allocator); + allocator.destroy(self.contents.module); self.status = .unloaded_sema_failure; }, .loaded_parse_failure => { @@ -603,7 +605,14 @@ pub const Module = struct { } self.failed_exports.deinit(); } - self.decl_exports.deinit(); + { + var it = self.decl_exports.iterator(); + while (it.next()) |kv| { + const export_list = kv.value; + allocator.free(export_list); + } + self.decl_exports.deinit(); + } { var it = self.export_owners.iterator(); while (it.next()) |kv| { @@ -613,7 +622,7 @@ pub const Module = struct { } allocator.free(export_list); } - self.failed_exports.deinit(); + self.export_owners.deinit(); } self.root_pkg.destroy(); {