authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-02-06 21:36:41+01:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-02-07 00:17:23-05:00
log9211938e6ee8d84ce7a70b9193ed08f7e0b5aa95
treed5b8cb8f5f44cd9997b50f85dd5a55e0bec443b4
parent38c2a257354a7a3c638bf15b930305f1249c368a

Elf: fix memory leaks


1 files changed, 8 insertions(+), 8 deletions(-)

src/link/Elf.zig+8-8
...@@ -1164,10 +1164,10 @@ pub fn flushModule(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node)...@@ -1164,10 +1164,10 @@ pub fn flushModule(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node)
11641164
1165 success: {1165 success: {
1166 if (!self.base.isStatic()) {1166 if (!self.base.isStatic()) {
1167 if (try self.accessLibPath(&test_path, &checked_paths, lc.crt_dir.?, lib_name, .Dynamic))1167 if (try self.accessLibPath(arena, &test_path, &checked_paths, lc.crt_dir.?, lib_name, .Dynamic))
1168 break :success;1168 break :success;
1169 }1169 }
1170 if (try self.accessLibPath(&test_path, &checked_paths, lc.crt_dir.?, lib_name, .Static))1170 if (try self.accessLibPath(arena, &test_path, &checked_paths, lc.crt_dir.?, lib_name, .Static))
1171 break :success;1171 break :success;
11721172
1173 try self.reportMissingLibraryError(1173 try self.reportMissingLibraryError(
...@@ -1997,10 +1997,10 @@ fn parseLdScript(self: *Elf, lib: SystemLib) ParseError!void {...@@ -1997,10 +1997,10 @@ fn parseLdScript(self: *Elf, lib: SystemLib) ParseError!void {
1997 // Maybe we should hoist search-strategy all the way here?1997 // Maybe we should hoist search-strategy all the way here?
1998 for (self.lib_dirs) |lib_dir| {1998 for (self.lib_dirs) |lib_dir| {
1999 if (!self.base.isStatic()) {1999 if (!self.base.isStatic()) {
2000 if (try self.accessLibPath(&test_path, &checked_paths, lib_dir, lib_name, .Dynamic))2000 if (try self.accessLibPath(arena, &test_path, &checked_paths, lib_dir, lib_name, .Dynamic))
2001 break :success;2001 break :success;
2002 }2002 }
2003 if (try self.accessLibPath(&test_path, &checked_paths, lib_dir, lib_name, .Static))2003 if (try self.accessLibPath(arena, &test_path, &checked_paths, lib_dir, lib_name, .Static))
2004 break :success;2004 break :success;
2005 }2005 }
2006 } else {2006 } else {
...@@ -2011,9 +2011,9 @@ fn parseLdScript(self: *Elf, lib: SystemLib) ParseError!void {...@@ -2011,9 +2011,9 @@ fn parseLdScript(self: *Elf, lib: SystemLib) ParseError!void {
2011 break :success;2011 break :success;
2012 } else |_| {}2012 } else |_| {}
20132013
2014 try checked_paths.append(try gpa.dupe(u8, scr_obj.path));2014 try checked_paths.append(try arena.dupe(u8, scr_obj.path));
2015 for (self.lib_dirs) |lib_dir| {2015 for (self.lib_dirs) |lib_dir| {
2016 if (try self.accessLibPath(&test_path, &checked_paths, lib_dir, scr_obj.path, null))2016 if (try self.accessLibPath(arena, &test_path, &checked_paths, lib_dir, scr_obj.path, null))
2017 break :success;2017 break :success;
2018 }2018 }
2019 }2019 }
...@@ -2046,13 +2046,13 @@ fn parseLdScript(self: *Elf, lib: SystemLib) ParseError!void {...@@ -2046,13 +2046,13 @@ fn parseLdScript(self: *Elf, lib: SystemLib) ParseError!void {
20462046
2047fn accessLibPath(2047fn accessLibPath(
2048 self: *Elf,2048 self: *Elf,
2049 arena: Allocator,
2049 test_path: *std.ArrayList(u8),2050 test_path: *std.ArrayList(u8),
2050 checked_paths: ?*std.ArrayList([]const u8),2051 checked_paths: ?*std.ArrayList([]const u8),
2051 lib_dir_path: []const u8,2052 lib_dir_path: []const u8,
2052 lib_name: []const u8,2053 lib_name: []const u8,
2053 link_mode: ?std.builtin.LinkMode,2054 link_mode: ?std.builtin.LinkMode,
2054) !bool {2055) !bool {
2055 const gpa = self.base.comp.gpa;
2056 const sep = fs.path.sep_str;2056 const sep = fs.path.sep_str;
2057 const target = self.base.comp.root_mod.resolved_target.result;2057 const target = self.base.comp.root_mod.resolved_target.result;
2058 test_path.clearRetainingCapacity();2058 test_path.clearRetainingCapacity();
...@@ -2068,7 +2068,7 @@ fn accessLibPath(...@@ -2068,7 +2068,7 @@ fn accessLibPath(
2068 suffix,2068 suffix,
2069 });2069 });
2070 if (checked_paths) |cpaths| {2070 if (checked_paths) |cpaths| {
2071 try cpaths.append(try gpa.dupe(u8, test_path.items));2071 try cpaths.append(try arena.dupe(u8, test_path.items));
2072 }2072 }
2073 fs.cwd().access(test_path.items, .{}) catch |err| switch (err) {2073 fs.cwd().access(test_path.items, .{}) catch |err| switch (err) {
2074 error.FileNotFound => return false,2074 error.FileNotFound => return false,