authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-11-16 21:22:43-05:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-11-16 21:29:17-05:00
log5be8a5fe5f25064ce963fa7a38942e387254de8d
tree7ffdabbcd87861a8cc0f646120d0b59b54cd1a96
parenta8ec306b493ddac701f279bfe82808525956f3f2

link: fix memory bugs


2 files changed, 5 insertions(+), 2 deletions(-)

src/link/Elf/SharedObject.zig+1
......@@ -72,6 +72,7 @@ pub const Parsed = struct {
7272
7373 pub fn deinit(p: *Parsed, gpa: Allocator) void {
7474 gpa.free(p.strtab);
75 gpa.free(p.sections);
7576 gpa.free(p.symtab);
7677 gpa.free(p.versyms);
7778 gpa.free(p.symbols);
src/main.zig+4-2
......@@ -984,6 +984,7 @@ fn buildOutputType(
984984 .libc_paths_file = try EnvVar.ZIG_LIBC.get(arena),
985985 .native_system_include_paths = &.{},
986986 };
987 defer create_module.link_inputs.deinit(gpa);
987988
988989 // before arg parsing, check for the NO_COLOR and CLICOLOR_FORCE environment variables
989990 // if set, default the color setting to .off or .on, respectively
......@@ -3682,7 +3683,7 @@ const CreateModule = struct {
36823683 /// This one is used while collecting CLI options. The set of libs is used
36833684 /// directly after computing the target and used to compute link_libc,
36843685 /// link_libcpp, and then the libraries are filtered into
3685 /// `unresolved_linker_inputs` and `windows_libs`.
3686 /// `unresolved_link_inputs` and `windows_libs`.
36863687 cli_link_inputs: std.ArrayListUnmanaged(link.UnresolvedInput),
36873688 windows_libs: std.StringArrayHashMapUnmanaged(void),
36883689 /// The local variable `unresolved_link_inputs` is fed into library
......@@ -3816,7 +3817,8 @@ fn createModule(
38163817 // to decide whether to trigger native path detection logic.
38173818 // Preserves linker input order.
38183819 var unresolved_link_inputs: std.ArrayListUnmanaged(link.UnresolvedInput) = .empty;
3819 try unresolved_link_inputs.ensureUnusedCapacity(arena, create_module.cli_link_inputs.items.len);
3820 defer unresolved_link_inputs.deinit(gpa);
3821 try unresolved_link_inputs.ensureUnusedCapacity(gpa, create_module.cli_link_inputs.items.len);
38203822 var any_name_queries_remaining = false;
38213823 for (create_module.cli_link_inputs.items) |cli_link_input| switch (cli_link_input) {
38223824 .name_query => |nq| {