mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
macho+wasm: unify and clean up closing file handles
This commit is contained in:
parent
639237c7b4
commit
678e07b924
@ -1437,7 +1437,6 @@ fn parseArchive(self: *MachO, path: []const u8, force_load: bool) !bool {
|
||||
|
||||
if (force_load) {
|
||||
defer archive.deinit(gpa);
|
||||
defer file.close();
|
||||
// Get all offsets from the ToC
|
||||
var offsets = std.AutoArrayHashMap(u32, void).init(gpa);
|
||||
defer offsets.deinit();
|
||||
@ -3015,7 +3014,6 @@ pub fn deinit(self: *MachO) void {
|
||||
}
|
||||
|
||||
if (self.d_sym) |*d_sym| {
|
||||
d_sym.file.close();
|
||||
d_sym.deinit(gpa);
|
||||
}
|
||||
|
||||
@ -3044,7 +3042,6 @@ pub fn deinit(self: *MachO) void {
|
||||
self.objects.deinit(gpa);
|
||||
|
||||
for (self.archives.items) |*archive| {
|
||||
archive.file.close();
|
||||
archive.deinit(gpa);
|
||||
}
|
||||
self.archives.deinit(gpa);
|
||||
|
||||
@ -88,6 +88,7 @@ const ar_hdr = extern struct {
|
||||
};
|
||||
|
||||
pub fn deinit(self: *Archive, allocator: Allocator) void {
|
||||
self.file.close();
|
||||
for (self.toc.keys()) |*key| {
|
||||
allocator.free(key.*);
|
||||
}
|
||||
|
||||
@ -306,6 +306,7 @@ pub fn flushModule(self: *DebugSymbols, allocator: Allocator, options: link.Opti
|
||||
}
|
||||
|
||||
pub fn deinit(self: *DebugSymbols, allocator: Allocator) void {
|
||||
self.file.close();
|
||||
self.segments.deinit(allocator);
|
||||
self.sections.deinit(allocator);
|
||||
self.dwarf.deinit();
|
||||
|
||||
@ -648,12 +648,10 @@ pub fn deinit(self: *Wasm) void {
|
||||
gpa.free(segment_info.name);
|
||||
}
|
||||
for (self.objects.items) |*object| {
|
||||
object.file.?.close();
|
||||
object.deinit(gpa);
|
||||
}
|
||||
|
||||
for (self.archives.items) |*archive| {
|
||||
archive.file.close();
|
||||
archive.deinit(gpa);
|
||||
}
|
||||
|
||||
|
||||
@ -95,6 +95,7 @@ const ar_hdr = extern struct {
|
||||
};
|
||||
|
||||
pub fn deinit(archive: *Archive, allocator: Allocator) void {
|
||||
archive.file.close();
|
||||
for (archive.toc.keys()) |*key| {
|
||||
allocator.free(key.*);
|
||||
}
|
||||
|
||||
@ -141,6 +141,9 @@ pub fn create(gpa: Allocator, file: std.fs.File, name: []const u8, maybe_max_siz
|
||||
/// Frees all memory of `Object` at once. The given `Allocator` must be
|
||||
/// the same allocator that was used when `init` was called.
|
||||
pub fn deinit(self: *Object, gpa: Allocator) void {
|
||||
if (self.file) |file| {
|
||||
file.close();
|
||||
}
|
||||
for (self.func_types) |func_ty| {
|
||||
gpa.free(func_ty.params);
|
||||
gpa.free(func_ty.returns);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user