fix memory leaks
This commit is contained in:
@@ -538,6 +538,7 @@ fn resolveSymbolsInArchives(self: *Wasm) !void {
|
||||
continue;
|
||||
};
|
||||
|
||||
log.debug("Detected symbol '{s}' in archive '{s}', parsing objects..", .{ sym_name, archive.name });
|
||||
// Symbol is found in unparsed object file within current archive.
|
||||
// Parse object and and resolve symbols again before we check remaining
|
||||
// undefined symbols.
|
||||
@@ -581,11 +582,17 @@ pub fn deinit(self: *Wasm) void {
|
||||
object.deinit(gpa);
|
||||
}
|
||||
|
||||
for (self.archives.items) |*archive| {
|
||||
archive.file.close();
|
||||
archive.deinit(gpa);
|
||||
}
|
||||
|
||||
self.decls.deinit(gpa);
|
||||
self.symbols.deinit(gpa);
|
||||
self.symbols_free_list.deinit(gpa);
|
||||
self.globals.deinit(gpa);
|
||||
self.resolved_symbols.deinit(gpa);
|
||||
self.undefs.deinit(gpa);
|
||||
self.discarded.deinit(gpa);
|
||||
self.symbol_atom.deinit(gpa);
|
||||
self.export_names.deinit(gpa);
|
||||
@@ -599,6 +606,7 @@ pub fn deinit(self: *Wasm) void {
|
||||
self.data_segments.deinit(gpa);
|
||||
self.segment_info.deinit(gpa);
|
||||
self.objects.deinit(gpa);
|
||||
self.archives.deinit(gpa);
|
||||
|
||||
// free output sections
|
||||
self.imports.deinit(gpa);
|
||||
@@ -1838,10 +1846,10 @@ pub fn flushModule(self: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod
|
||||
|
||||
try self.parseInputFiles(positionals.items);
|
||||
|
||||
var object_index: u16 = 0;
|
||||
while (object_index < self.objects.items.len) : (object_index += 1) {
|
||||
try self.resolveSymbolsInObject(object_index);
|
||||
for (self.objects.items) |_, object_index| {
|
||||
try self.resolveSymbolsInObject(@intCast(u16, object_index));
|
||||
}
|
||||
|
||||
try self.resolveSymbolsInArchives();
|
||||
|
||||
// When we finish/error we reset the state of the linker
|
||||
@@ -1867,9 +1875,8 @@ pub fn flushModule(self: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod
|
||||
}
|
||||
}
|
||||
|
||||
while (object_index > 0) {
|
||||
object_index -= 1;
|
||||
try self.objects.items[object_index].parseIntoAtoms(self.base.allocator, object_index, self);
|
||||
for (self.objects.items) |*object, object_index| {
|
||||
try object.parseIntoAtoms(self.base.allocator, @intCast(u16, object_index), self);
|
||||
}
|
||||
|
||||
if (self.dwarf) |*dwarf| {
|
||||
|
||||
@@ -95,7 +95,6 @@ pub fn deinit(self: *Archive, allocator: Allocator) void {
|
||||
value.deinit(allocator);
|
||||
}
|
||||
self.toc.deinit(allocator);
|
||||
allocator.free(self.name);
|
||||
}
|
||||
|
||||
pub fn parse(self: *Archive, allocator: Allocator) !void {
|
||||
|
||||
@@ -75,7 +75,7 @@ pub fn clear(self: *Atom) void {
|
||||
pub fn format(self: Atom, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
|
||||
_ = fmt;
|
||||
_ = options;
|
||||
writer.print("Atom{{ .sym_index = {d}, .alignment = {d}, .size = {d}, .offset = 0x{x:0>8} }}", .{
|
||||
try writer.print("Atom{{ .sym_index = {d}, .alignment = {d}, .size = {d}, .offset = 0x{x:0>8} }}", .{
|
||||
self.sym_index,
|
||||
self.alignment,
|
||||
self.size,
|
||||
|
||||
@@ -813,7 +813,9 @@ pub fn parseIntoAtoms(self: *Object, gpa: Allocator, object_index: u16, wasm_bin
|
||||
index: u32,
|
||||
};
|
||||
var symbol_for_segment = std.AutoArrayHashMap(Key, std.ArrayList(u32)).init(gpa);
|
||||
defer symbol_for_segment.deinit();
|
||||
defer for (symbol_for_segment.values()) |*list| {
|
||||
list.deinit();
|
||||
} else symbol_for_segment.deinit();
|
||||
|
||||
for (self.symtable) |symbol, symbol_index| {
|
||||
switch (symbol.tag) {
|
||||
|
||||
Reference in New Issue
Block a user