From 5be8a5fe5f25064ce963fa7a38942e387254de8d Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Sat, 16 Nov 2024 21:22:43 -0500 Subject: [PATCH] link: fix memory bugs --- src/link/Elf/SharedObject.zig | 1 + src/main.zig | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/link/Elf/SharedObject.zig b/src/link/Elf/SharedObject.zig index 8b4f482226..ac3b3857a1 100644 --- a/src/link/Elf/SharedObject.zig +++ b/src/link/Elf/SharedObject.zig @@ -72,6 +72,7 @@ pub const Parsed = struct { pub fn deinit(p: *Parsed, gpa: Allocator) void { gpa.free(p.strtab); + gpa.free(p.sections); gpa.free(p.symtab); gpa.free(p.versyms); gpa.free(p.symbols); diff --git a/src/main.zig b/src/main.zig index 9b245b3eda..291820cb75 100644 --- a/src/main.zig +++ b/src/main.zig @@ -984,6 +984,7 @@ fn buildOutputType( .libc_paths_file = try EnvVar.ZIG_LIBC.get(arena), .native_system_include_paths = &.{}, }; + defer create_module.link_inputs.deinit(gpa); // before arg parsing, check for the NO_COLOR and CLICOLOR_FORCE environment variables // if set, default the color setting to .off or .on, respectively @@ -3682,7 +3683,7 @@ const CreateModule = struct { /// This one is used while collecting CLI options. The set of libs is used /// directly after computing the target and used to compute link_libc, /// link_libcpp, and then the libraries are filtered into - /// `unresolved_linker_inputs` and `windows_libs`. + /// `unresolved_link_inputs` and `windows_libs`. cli_link_inputs: std.ArrayListUnmanaged(link.UnresolvedInput), windows_libs: std.StringArrayHashMapUnmanaged(void), /// The local variable `unresolved_link_inputs` is fed into library @@ -3816,7 +3817,8 @@ fn createModule( // to decide whether to trigger native path detection logic. // Preserves linker input order. var unresolved_link_inputs: std.ArrayListUnmanaged(link.UnresolvedInput) = .empty; - try unresolved_link_inputs.ensureUnusedCapacity(arena, create_module.cli_link_inputs.items.len); + defer unresolved_link_inputs.deinit(gpa); + try unresolved_link_inputs.ensureUnusedCapacity(gpa, create_module.cli_link_inputs.items.len); var any_name_queries_remaining = false; for (create_module.cli_link_inputs.items) |cli_link_input| switch (cli_link_input) { .name_query => |nq| {