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)
11641164
11651165 success: {
11661166 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))
11681168 break :success;
11691169 }
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))
11711171 break :success;
11721172
11731173 try self.reportMissingLibraryError(
......@@ -1997,10 +1997,10 @@ fn parseLdScript(self: *Elf, lib: SystemLib) ParseError!void {
19971997 // Maybe we should hoist search-strategy all the way here?
19981998 for (self.lib_dirs) |lib_dir| {
19991999 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))
20012001 break :success;
20022002 }
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))
20042004 break :success;
20052005 }
20062006 } else {
......@@ -2011,9 +2011,9 @@ fn parseLdScript(self: *Elf, lib: SystemLib) ParseError!void {
20112011 break :success;
20122012 } 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));
20152015 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))
20172017 break :success;
20182018 }
20192019 }
......@@ -2046,13 +2046,13 @@ fn parseLdScript(self: *Elf, lib: SystemLib) ParseError!void {
20462046
20472047fn accessLibPath(
20482048 self: *Elf,
2049 arena: Allocator,
20492050 test_path: *std.ArrayList(u8),
20502051 checked_paths: ?*std.ArrayList([]const u8),
20512052 lib_dir_path: []const u8,
20522053 lib_name: []const u8,
20532054 link_mode: ?std.builtin.LinkMode,
20542055) !bool {
2055 const gpa = self.base.comp.gpa;
20562056 const sep = fs.path.sep_str;
20572057 const target = self.base.comp.root_mod.resolved_target.result;
20582058 test_path.clearRetainingCapacity();
......@@ -2068,7 +2068,7 @@ fn accessLibPath(
20682068 suffix,
20692069 });
20702070 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));
20722072 }
20732073 fs.cwd().access(test_path.items, .{}) catch |err| switch (err) {
20742074 error.FileNotFound => return false,