CBE: Improve resource cleanup

This commit is contained in:
Noam Preil 2020-07-07 23:24:30 -04:00
parent 7a6104929b
commit 089c056dbe
No known key found for this signature in database
GPG Key ID: FC347E7C85BE8238
2 changed files with 18 additions and 3 deletions

View File

@ -744,7 +744,7 @@ pub fn init(gpa: *Allocator, options: InitOptions) !Module {
.object_format = options.object_format orelse options.target.getObjectFormat(),
.cbe = options.cbe,
});
errdefer bin_file.*.deinit();
errdefer bin_file.destroy();
const root_scope = blk: {
if (mem.endsWith(u8, options.root_pkg.root_src_path, ".zig")) {
@ -793,9 +793,8 @@ pub fn init(gpa: *Allocator, options: InitOptions) !Module {
}
pub fn deinit(self: *Module) void {
self.bin_file.deinit();
self.bin_file.destroy();
const allocator = self.allocator;
allocator.destroy(self.bin_file);
self.deletion_set.deinit(allocator);
self.work_queue.deinit();

View File

@ -159,6 +159,22 @@ pub const File = struct {
}
}
pub fn destroy(base: *File) void {
switch (base.tag) {
.Elf => {
const parent = @fieldParentPtr(Elf, "base", base);
parent.deinit();
parent.allocator.destroy(parent);
},
.C => {
const parent = @fieldParentPtr(C, "base", base);
parent.deinit();
parent.allocator.destroy(parent);
},
else => unreachable,
}
}
pub fn flush(base: *File) !void {
try switch (base.tag) {
.Elf => @fieldParentPtr(Elf, "base", base).flush(),